diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2007-06-30 22:35:23 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2007-06-30 22:35:23 +0000 |
commit | f7e1590c5e290f640f1f2f5bda93be265ed87eb5 (patch) | |
tree | 81525459024e64ace6fbfcffe16710f4946da220 /nuttx/examples | |
parent | bfd3548a9c9f152407bd1b57d4bcaf5a534d7d77 (diff) | |
download | px4-nuttx-f7e1590c5e290f640f1f2f5bda93be265ed87eb5.tar.gz px4-nuttx-f7e1590c5e290f640f1f2f5bda93be265ed87eb5.tar.bz2 px4-nuttx-f7e1590c5e290f640f1f2f5bda93be265ed87eb5.zip |
Add a test of environment variables
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@297 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/examples')
-rw-r--r-- | nuttx/examples/ostest/main.c | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/nuttx/examples/ostest/main.c b/nuttx/examples/ostest/main.c index b9d80ff8e..889eeaefa 100644 --- a/nuttx/examples/ostest/main.c +++ b/nuttx/examples/ostest/main.c @@ -89,6 +89,21 @@ static struct mallinfo g_mmprevious; static struct mallinfo g_mmafter; #endif +#ifndef CONFIG_DISABLE_ENVIRON +const char g_var1_name[] = "Variable1"; +const char g_var1_value[] = "GoodValue1"; +const char g_var2_name[] = "Variable2"; +const char g_var2_value[] = "GoodValue2"; +const char g_var3_name[] = "Variable3"; +const char g_var3_value[] = "GoodValue3"; + +const char g_bad_value1[] = "BadValue1"; +const char g_bad_value2[] = "BadValue2"; + +const char g_putenv_value[] = "Variable1=BadValue3"; + +#endif + /************************************************************ * Private Functions ************************************************************/ @@ -150,6 +165,55 @@ static void check_test_memory_usage(void) #endif /************************************************************ + * Name: show_environment + ************************************************************/ + +#ifndef CONFIG_DISABLE_ENVIRON +static void show_variable(const char *var_name, const char *exptd_value, boolean var_valid) +{ + char *actual_value = getenv(var_name); + if (actual_value) + { + if (var_valid) + { + if (strcmp(actual_value, exptd_value) == 0) + { + printf("show_variable: Variable=%s has value=%s\n", var_name, exptd_value); + } + else + { + printf("show_variable: ERROR Variable=%s has the wrong value\n", var_name); + printf("show_variable: found=%s expected=%s\n", actual_value, exptd_value); + } + } + else + { + printf("show_variable: ERROR Variable=%s has a value when it should not\n", var_name); + printf("show_variable: value=%s\n", actual_value); + } + } + else if (var_valid) + { + printf("show_variable: ERROR Variable=%s has no value\n", var_name); + printf("show_variable: Should have had value=%s\n", exptd_value); + } + else + { + printf("show_variable: Variable=%s has no value\n", var_name); + } +} + +static show_environment(boolean var1_valid, boolean var2_valid, boolean var3_valid) +{ + show_variable( g_var1_name, g_var1_value, var1_valid); + show_variable( g_var2_name, g_var2_value, var2_valid); + show_variable( g_var3_name, g_var3_value, var3_valid); +} +#else +# define show_environment() +#endif + +/************************************************************ * Name: user_main ************************************************************/ @@ -197,6 +261,19 @@ static int user_main(int argc, char *argv[]) } check_test_memory_usage(); + /* Check environment variables */ +#ifndef CONFIG_DISABLE_ENVIRON + show_environment(TRUE, TRUE, TRUE); + + unsetenv(g_var1_name); + show_environment(FALSE, TRUE, TRUE); + check_test_memory_usage(); + + clearenv(); + show_environment(FALSE, FALSE, FALSE); + check_test_memory_usage(); +#endif + #if CONFIG_NFILE_DESCRIPTORS > 0 /* Checkout /dev/null */ @@ -374,6 +451,26 @@ int user_start(int argc, char *argv[]) g_argv[4] = NULL; #endif + /* Set up some environment variables */ + +#ifndef CONFIG_DISABLE_ENVIRON + printf("user_start: putenv(%s)\n", g_putenv_value); + putenv(g_putenv_value); /* Varaible1=BadValue3 */ + printf("user_start: setenv(%s, %s, TRUE)\n", g_var1_name, g_var1_value); + setenv(g_var1_name, g_var1_value, TRUE); /* Variable1=GoodValue1 */ + + printf("user_start: setenv(%s, %s, FALSE)\n", g_var2_name, g_bad_value1); + setenv(g_var2_name, g_bad_value1, FALSE); /* Variable2=BadValue1 */ + printf("user_start: setenv(%s, %s, TRUE)\n", g_var2_name, g_var2_value); + setenv(g_var2_name, g_var2_value, TRUE); /* Variable2=GoodValue2 */ + + printf("user_start: setenv(%s, %s, FALSE)\n", g_var3_name, g_var3_name); + setenv(g_var3_name, g_var3_value, FALSE); /* Variable3=GoodValue3 */ + printf("user_start: setenv(%s, %s, FALSE)\n", g_var3_name, g_var3_name); + setenv(g_var3_name, g_bad_value2, FALSE); /* Variable3=GoodValue3 */ + show_environment(TRUE, TRUE, TRUE); +#endif + /* Verify that we can spawn a new task */ #ifndef CONFIG_CUSTOM_STACK |