Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quelle  testing.h

  Sprache: C
 

/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


#ifndef ART_LIBARTTOOLS_INCLUDE_TESTING_TOOLS_TESTING_H_
#define ART_LIBARTTOOLS_INCLUDE_TESTING_TOOLS_TESTING_H_

#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <unistd.h>

#include <functional>
#include <memory>
#include <string>
#include <utility>
#include <vector>

#include "android-base/logging.h"
#include "android-base/scopeguard.h"
#include "android-base/strings.h"
#include "base/file_utils.h"
#include "base/globals.h"
#include "base/macros.h"

namespace art {
namespace tools {

using ::android::base::make_scope_guard;
using ::android::base::ScopeGuard;
using ::android::base::Split;

[[maybe_unused]] static std::string GetArtBin(const std::string& name) {
  CHECK(kIsTargetAndroid);
  return ART_FORMAT("{}/bin/{}", GetArtRoot(), name);
}

[[maybe_unused]] static std::string GetBin(const std::string& name) {
  for (const std::string& path : Split(getenv("PATH"), ":")) {
    if (std::filesystem::exists(path + "/" + name)) {
      return path + "/" + name;
    }
  }
  LOG(FATAL) << ART_FORMAT("Binary '{}' not found", name);
  UNREACHABLE();
}

// Executes the command. If `wait` is true, waits for the process to finish and keeps it in a
// waitable state; otherwise, returns immediately after fork. When the current scope exits, destroys
// the process.
[[maybe_unused]] static std::pair<pid_t, std::unique_ptr<ScopeGuard<std::function<void()>>>>
ScopedExec(std::vector<std::string>& args, bool wait) {
  std::vector<char*> execv_args;
  execv_args.reserve(args.size() + 1);
  for (std::string& arg : args) {
    execv_args.push_back(arg.data());
  }
  execv_args.push_back(nullptr);

  pid_t pid = fork();
  if (pid == 0) {
    execv(execv_args[0], execv_args.data());
    PLOG(FATAL) << "Failed to call execv";
    UNREACHABLE();
  } else if (pid > 0) {
    if (wait) {
      siginfo_t info;
      CHECK_EQ(TEMP_FAILURE_RETRY(waitid(P_PID, pid, &info, WEXITED | WNOWAIT)), 0);
      CHECK_EQ(info.si_code, CLD_EXITED);
      CHECK_EQ(info.si_status, 0);
    }
    std::function<void()> cleanup([=] {
      siginfo_t info;
      if (!wait) {
        CHECK_EQ(kill(pid, SIGKILL), 0);
      }
      CHECK_EQ(TEMP_FAILURE_RETRY(waitid(P_PID, pid, &info, WEXITED)), 0);
    });
    return std::make_pair(
        pid,
        std::make_unique<ScopeGuard<std::function<void()>>>(make_scope_guard(std::move(cleanup))));
  } else {
    PLOG(FATAL) << "Failed to call fork";
    UNREACHABLE();
  }
}

}  // namespace tools
}  // namespace art

#endif  // ART_LIBARTTOOLS_INCLUDE_TESTING_TOOLS_TESTING_H_

Messung V0.5 in Prozent
C=89 H=98 G=93

¤ Dauer der Verarbeitung: 0.13 Sekunden  (vorverarbeitet am  2026-06-29) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Aktivitäten

     Artikel über Sicherheit
     Anleitung zur Aktivierung von SSL

Muße

     Gedichte
     Musik
     Bilder

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik