blob: 82bddba18f998fa6fcff81368bdf10b20fb7aaa9 [file] [log] [blame]
Johnny Chend5e111c2010-09-15 22:27:29 +00001//===-- main.cpp ------------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include <cstdlib>
11#include <string>
12#include <fstream>
Johnny Chenf7f62712010-09-15 22:48:40 +000013#include <iostream>
Johnny Chend5e111c2010-09-15 22:27:29 +000014
15int
16main(int argc, char const *argv[])
17{
Johnny Chena245f932010-12-14 23:43:29 +000018 // The program writes its output to the following file:
19 //
20 // o "output1.txt" for test_pass_host_env_vars() test case
21 // o "output2.txt" for test_run_args_and_env_vars_with_dsym() test case
22 // o "output2.txt" for test_run_args_and_env_vars_with_dwarf() test case
23 std::ofstream outfile;
24 if (argc == 1)
25 outfile.open("output1.txt");
26 else
27 outfile.open("output2.txt");
Johnny Chend5e111c2010-09-15 22:27:29 +000028
Johnny Chenf7f62712010-09-15 22:48:40 +000029 for (unsigned i = 0; i < argc; ++i) {
30 std::string theArg(argv[i]);
31 if (i == 1 && "A" == theArg)
Johnny Chend5e111c2010-09-15 22:27:29 +000032 outfile << "argv[1] matches\n";
33
Johnny Chenf7f62712010-09-15 22:48:40 +000034 if (i == 2 && "B" == theArg)
Johnny Chend5e111c2010-09-15 22:27:29 +000035 outfile << "argv[2] matches\n";
36
Johnny Chenf7f62712010-09-15 22:48:40 +000037 if (i == 3 && "C" == theArg)
Johnny Chend5e111c2010-09-15 22:27:29 +000038 outfile << "argv[3] matches\n";
39 }
40
Johnny Chen80554b82010-12-04 00:44:56 +000041 // For passing environment vars from the debugger to the launched process.
Johnny Chend5e111c2010-09-15 22:27:29 +000042 if (::getenv("MY_ENV_VAR")) {
43 std::string MY_ENV_VAR(getenv("MY_ENV_VAR"));
44 if ("YES" == MY_ENV_VAR) {
45 outfile << "Environment variable 'MY_ENV_VAR' successfully passed.\n";
46 }
47 }
48
Johnny Chen80554b82010-12-04 00:44:56 +000049
50 // For passing host environment vars to the launched process.
51 if (::getenv("MY_HOST_ENV_VAR1")) {
52 std::string MY_HOST_ENV_VAR1(getenv("MY_HOST_ENV_VAR1"));
53 if ("VAR1" == MY_HOST_ENV_VAR1) {
54 outfile << "The host environment variable 'MY_HOST_ENV_VAR1' successfully passed.\n";
55 }
56 }
57
58 if (::getenv("MY_HOST_ENV_VAR2")) {
59 std::string MY_HOST_ENV_VAR2(getenv("MY_HOST_ENV_VAR2"));
60 if ("VAR2" == MY_HOST_ENV_VAR2) {
61 outfile << "The host environment variable 'MY_HOST_ENV_VAR2' successfully passed.\n";
62 }
63 }
64
Johnny Chenf7f62712010-09-15 22:48:40 +000065 std::cout << "This message should go to standard out.\n";
66
Johnny Chena245f932010-12-14 23:43:29 +000067 outfile.close();
Johnny Chend5e111c2010-09-15 22:27:29 +000068 return 0;
69}