Johnny Chen | d5e111c | 2010-09-15 22:27:29 +0000 | [diff] [blame] | 1 | //===-- 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 Chen | f7f6271 | 2010-09-15 22:48:40 +0000 | [diff] [blame] | 13 | #include <iostream> |
Johnny Chen | d5e111c | 2010-09-15 22:27:29 +0000 | [diff] [blame] | 14 | |
| 15 | int |
| 16 | main(int argc, char const *argv[]) |
| 17 | { |
Johnny Chen | a245f93 | 2010-12-14 23:43:29 +0000 | [diff] [blame^] | 18 | // 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 Chen | d5e111c | 2010-09-15 22:27:29 +0000 | [diff] [blame] | 28 | |
Johnny Chen | f7f6271 | 2010-09-15 22:48:40 +0000 | [diff] [blame] | 29 | for (unsigned i = 0; i < argc; ++i) { |
| 30 | std::string theArg(argv[i]); |
| 31 | if (i == 1 && "A" == theArg) |
Johnny Chen | d5e111c | 2010-09-15 22:27:29 +0000 | [diff] [blame] | 32 | outfile << "argv[1] matches\n"; |
| 33 | |
Johnny Chen | f7f6271 | 2010-09-15 22:48:40 +0000 | [diff] [blame] | 34 | if (i == 2 && "B" == theArg) |
Johnny Chen | d5e111c | 2010-09-15 22:27:29 +0000 | [diff] [blame] | 35 | outfile << "argv[2] matches\n"; |
| 36 | |
Johnny Chen | f7f6271 | 2010-09-15 22:48:40 +0000 | [diff] [blame] | 37 | if (i == 3 && "C" == theArg) |
Johnny Chen | d5e111c | 2010-09-15 22:27:29 +0000 | [diff] [blame] | 38 | outfile << "argv[3] matches\n"; |
| 39 | } |
| 40 | |
Johnny Chen | 80554b8 | 2010-12-04 00:44:56 +0000 | [diff] [blame] | 41 | // For passing environment vars from the debugger to the launched process. |
Johnny Chen | d5e111c | 2010-09-15 22:27:29 +0000 | [diff] [blame] | 42 | 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 Chen | 80554b8 | 2010-12-04 00:44:56 +0000 | [diff] [blame] | 49 | |
| 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 Chen | f7f6271 | 2010-09-15 22:48:40 +0000 | [diff] [blame] | 65 | std::cout << "This message should go to standard out.\n"; |
| 66 | |
Johnny Chen | a245f93 | 2010-12-14 23:43:29 +0000 | [diff] [blame^] | 67 | outfile.close(); |
Johnny Chen | d5e111c | 2010-09-15 22:27:29 +0000 | [diff] [blame] | 68 | return 0; |
| 69 | } |