DECLARE_TEST( environment, builtin ) { char const* const* cmdline = environment_command_line(); EXPECT_GE( array_size( cmdline ), 1 ); #if !FOUNDATION_PLATFORM_ANDROID && !FOUNDATION_PLATFORM_IOS EXPECT_NE( string_find_string( cmdline[0], "test-environment", 0 ), STRING_NPOS ); EXPECT_STREQ( environment_executable_name(), "test-environment" ); #endif EXPECT_NE( environment_initial_working_directory(), 0 ); EXPECT_NE( string_length( environment_initial_working_directory() ), 0 ); EXPECT_STREQ( environment_initial_working_directory(), environment_current_working_directory() ); EXPECT_NE( environment_home_directory(), 0 ); EXPECT_NE( string_length( environment_home_directory() ), 0 ); EXPECT_NE( environment_temporary_directory(), 0 ); EXPECT_NE( string_length( environment_temporary_directory() ), 0 ); EXPECT_NE( environment_variable( "PATH" ), 0 ); EXPECT_NE( string_length( environment_variable( "PATH" ) ), 0 ); return 0; }
DECLARE_TEST(environment, builtin) { const string_const_t* cmdline = environment_command_line(); EXPECT_GE(array_size(cmdline), 1); #if !BUILD_MONOLITHIC EXPECT_NE_MSGFORMAT(string_find_string(STRING_ARGS(cmdline[0]), STRING_CONST("test-environment"), 0), STRING_NPOS, "Commandline: %.*s", (int)cmdline[0].length, cmdline[0].str); EXPECT_CONSTSTRINGEQ(environment_executable_name(), string_const(STRING_CONST("test-environment"))); #elif FOUNDATION_PLATFORM_ANDROID EXPECT_NE_MSGFORMAT(string_find_string(STRING_ARGS(cmdline[0]), STRING_CONST("com.rampantpixels.foundation.test"), 0), STRING_NPOS, "Commandline: %.*s", (int)cmdline[0].length, cmdline[0].str); #elif !FOUNDATION_PLATFORM_PNACL EXPECT_NE_MSGFORMAT(string_find_string(STRING_ARGS(cmdline[0]), STRING_CONST("test-all"), 0), STRING_NPOS, "Commandline: %.*s", (int)cmdline[0].length, cmdline[0].str); EXPECT_CONSTSTRINGEQ(environment_executable_name(), string_const(STRING_CONST("test-all"))); #endif EXPECT_NE(environment_initial_working_directory().str, 0); EXPECT_NE(environment_initial_working_directory().length, 0); EXPECT_CONSTSTRINGEQ(environment_initial_working_directory(), environment_current_working_directory()); EXPECT_NE(environment_home_directory().str, 0); EXPECT_NE(environment_home_directory().length, 0); EXPECT_NE(environment_temporary_directory().str, 0); EXPECT_NE(environment_temporary_directory().length, 0); #if !FOUNDATION_PLATFORM_PNACL EXPECT_NE(environment_variable(STRING_CONST("PATH")).str, 0); EXPECT_NE(environment_variable(STRING_CONST("PATH")).length, 0); #endif return 0; }
DECLARE_TEST( environment, builtin ) { char const* const* cmdline = environment_command_line(); EXPECT_GE( array_size( cmdline ), 1 ); #if !BUILD_MONOLITHIC EXPECT_NE_MSGFORMAT( string_find_string( cmdline[0], "test-environment", 0 ), STRING_NPOS, "Commandline: %s", cmdline[0] ); EXPECT_STREQ( environment_executable_name(), "test-environment" ); #elif FOUNDATION_PLATFORM_ANDROID EXPECT_NE_MSGFORMAT( string_find_string( cmdline[0], "com.rampantpixels.foundation.test", 0 ), STRING_NPOS, "Commandline: %s", cmdline[0] ); #elif !FOUNDATION_PLATFORM_PNACL EXPECT_NE_MSGFORMAT( string_find_string( cmdline[0], "test-all", 0 ), STRING_NPOS, "Commandline: %s", cmdline[0] ); EXPECT_STREQ( environment_executable_name(), "test-all" ); #endif EXPECT_NE( environment_initial_working_directory(), 0 ); EXPECT_NE( string_length( environment_initial_working_directory() ), 0 ); EXPECT_STREQ( environment_initial_working_directory(), environment_current_working_directory() ); EXPECT_NE( environment_home_directory(), 0 ); EXPECT_NE( string_length( environment_home_directory() ), 0 ); EXPECT_NE( environment_temporary_directory(), 0 ); EXPECT_NE( string_length( environment_temporary_directory() ), 0 ); #if !FOUNDATION_PLATFORM_PNACL EXPECT_NE( environment_variable( "PATH" ), 0 ); EXPECT_NE( string_length( environment_variable( "PATH" ) ), 0 ); #endif return 0; }
int main_initialize(void) { foundation_config_t config; application_t application; int ret; size_t iarg, asize; const string_const_t* cmdline = environment_command_line(); _test_memory_tracker = true; for (iarg = 0, asize = array_size(cmdline); iarg < asize; ++iarg) { if (string_equal(STRING_ARGS(cmdline[iarg]), STRING_CONST("--no-memory-tracker"))) _test_memory_tracker = false; } if (_test_memory_tracker) memory_set_tracker(memory_tracker_local()); memset(&config, 0, sizeof(config)); memset(&application, 0, sizeof(application)); application.name = string_const(STRING_CONST("Task library test suite")); application.short_name = string_const(STRING_CONST("test_all")); application.company = string_const(STRING_CONST("Rampant Pixels")); application.version = task_module_version(); application.flags = APPLICATION_UTILITY; application.exception_handler = test_exception_handler; log_set_suppress(0, ERRORLEVEL_INFO); #if ( FOUNDATION_PLATFORM_IOS || FOUNDATION_PLATFORM_ANDROID ) && BUILD_ENABLE_LOG log_set_handler(test_log_handler); #endif #if !FOUNDATION_PLATFORM_IOS && !FOUNDATION_PLATFORM_ANDROID && !FOUNDATION_PLATFORM_PNACL _test_should_start = true; #endif ret = foundation_initialize(memory_system_malloc(), application, config); #if BUILD_MONOLITHIC if (ret == 0) { task_config_t task_config; memset(&task_config, 0, sizeof(task_config)); ret = task_module_initialize(task_config); test_set_suitable_working_directory(); } #endif return ret; }
int main_run(void* main_arg) { int result = RENDERCOMPILE_RESULT_OK; rendercompile_input_t input = rendercompile_parse_command_line(environment_command_line()); FOUNDATION_UNUSED(main_arg); if (input.display_help) { rendercompile_print_usage(); goto exit; } resource_source_set_path(STRING_ARGS(input.source_path)); resource_compile_register(render_compile); size_t ifile, fsize; for (ifile = 0, fsize = array_size(input.input_files); ifile < fsize; ++ifile) { uuid_t uuid = string_to_uuid(STRING_ARGS(input.input_files[ifile])); if (uuid_is_null(uuid)) { char buffer[BUILD_MAX_PATHLEN]; string_t pathstr = string_copy(buffer, sizeof(buffer), STRING_ARGS(input.input_files[ifile])); pathstr = path_clean(STRING_ARGS(pathstr), sizeof(buffer)); pathstr = path_absolute(STRING_ARGS(pathstr), sizeof(buffer)); uuid = resource_import_map_lookup(STRING_ARGS(pathstr)); } if (uuid_is_null(uuid)) { log_warnf(HASH_RESOURCE, WARNING_INVALID_VALUE, STRING_CONST("Failed to lookup: %.*s"), STRING_FORMAT(input.input_files[ifile])); result = RENDERCOMPILE_RESULT_INVALID_INPUT; break; } if (resource_compile(uuid, RESOURCE_PLATFORM_ALL)) { string_const_t uuidstr = string_from_uuid_static(uuid); log_infof(HASH_RESOURCE, STRING_CONST("Successfully compiled: %.*s (%.*s)"), STRING_FORMAT(uuidstr), STRING_FORMAT(input.input_files[ifile])); } else { string_const_t uuidstr = string_from_uuid_static(uuid); log_warnf(HASH_RESOURCE, WARNING_UNSUPPORTED, STRING_CONST("Failed to compile: %.*s (%.*s)"), STRING_FORMAT(uuidstr), STRING_FORMAT(input.input_files[ifile])); } } exit: array_deallocate(input.input_files); return result; }
int main_run( void* main_arg ) { int result = 0; hashify_input_t input = hashify_parse_command_line( environment_command_line() ); result = hashify_process_strings( (char const* const*)input.strings ); if( result < 0 ) goto exit; result = hashify_process_files( (char const* const*)input.files, input.check_only ); if( result < 0 ) goto exit; exit: string_array_deallocate( input.strings ); string_array_deallocate( input.files ); return result; }
int main_run( void* main_arg ) { int result = BIN2HEX_RESULT_OK; bin2hex_input_t input = bin2hex_parse_command_line( environment_command_line() ); if( !array_size( input.input_files ) ) bin2hex_print_usage(); else { result = bin2hex_process_files( (char const* const*)input.input_files, (char const* const*)input.output_files, input.columns ); if( result < 0 ) goto exit; } exit: string_array_deallocate( input.input_files ); string_array_deallocate( input.output_files ); return result; }
int foundation_initialize(const memory_system_t memory, const application_t application, const foundation_config_t config) { int ret = 0; if (_initialized) return 0; process_set_exit_code(PROCESS_EXIT_SUCCESS); foundation_initialize_config(config); /*lint -e774 */ SUBSYSTEM_INIT(atomic); SUBSYSTEM_INIT_ARGS(memory, memory); SUBSYSTEM_INIT(static_hash); SUBSYSTEM_INIT(log); SUBSYSTEM_INIT(time); SUBSYSTEM_INIT(thread); SUBSYSTEM_INIT(random); SUBSYSTEM_INIT(stream); SUBSYSTEM_INIT(fs); SUBSYSTEM_INIT(stacktrace); SUBSYSTEM_INIT(exception); SUBSYSTEM_INIT_ARGS(environment, application); SUBSYSTEM_INIT(library); SUBSYSTEM_INIT(system); if (ret) return ret; //Parse built-in command line options { /*lint --e{613} */ const string_const_t* cmdline = environment_command_line(); size_t iarg, argsize; for (iarg = 0, argsize = array_size(cmdline); iarg < argsize; ++iarg) { string_const_t arg = cmdline[iarg]; if (string_equal(arg.str, arg.length, STRING_CONST("--log-debug"))) log_set_suppress(0, ERRORLEVEL_NONE); else if (string_equal(arg.str, arg.length, STRING_CONST("--log-info"))) log_set_suppress(0, ERRORLEVEL_DEBUG); else if (string_equal(arg.str, arg.length, STRING_CONST("--log-warning"))) log_set_suppress(0, ERRORLEVEL_WARNING); else if (string_equal(arg.str, arg.length, STRING_CONST("--log-error"))) log_set_suppress(0, ERRORLEVEL_ERROR); } } #if !BUILD_DYNAMIC_LINK //Artificial references /*lint -e506 */ #if FOUNDATION_PLATFORM_ANDROID android_main(0); #elif FOUNDATION_PLATFORM_PNACL if (((uintptr_t)PPP_InitializeModule < 1) || ((uintptr_t)PPP_GetInterface < 1) || ((uintptr_t)PPP_ShutdownModule < 1)) return -1; #else if ((uintptr_t)main < 1) return -1; #endif #endif _initialized = true; return 0; }
void config_load( const char* name, hash_t filter_section, bool built_in, bool overwrite ) { /*lint --e{838} Safety null assign all pointers for all preprocessor paths */ /*lint --e{750} Unused macros in some paths */ #define NUM_SEARCH_PATHS 10 #define ANDROID_ASSET_PATH_INDEX 5 char* sub_exe_path = 0; char* exe_parent_path = 0; char* exe_processed_path = 0; char* abs_exe_parent_path = 0; char* abs_exe_processed_path = 0; char* bundle_path = 0; char* home_dir = 0; char* cmdline_path = 0; char* cwd_config_path = 0; const char* paths[NUM_SEARCH_PATHS]; #if !FOUNDATION_PLATFORM_FAMILY_MOBILE const char* const* cmd_line; int icl, clsize; #endif int start_path, i, j; const char buildsuffix[4][9] = { "/debug", "/release", "/profile", "/deploy" }; const char platformsuffix[7][14] = { "/win32", "/win64", "/osx", "/ios", "/android", "/raspberrypi", "/unknown" }; const char binsuffix[1][5] = { "/bin" }; FOUNDATION_ASSERT( name ); sub_exe_path = path_merge( environment_executable_directory(), "config" ); exe_parent_path = path_merge( environment_executable_directory(), "../config" ); abs_exe_parent_path = path_make_absolute( exe_parent_path ); exe_processed_path = string_clone( environment_executable_directory() ); for( i = 0; i < 4; ++i ) { if( string_ends_with( exe_processed_path, buildsuffix[i] ) ) { exe_processed_path[ string_length( exe_processed_path ) - string_length( buildsuffix[i] ) ] = 0; break; } } for( i = 0; i < 7; ++i ) { if( string_ends_with( exe_processed_path, platformsuffix[i] ) ) { exe_processed_path[ string_length( exe_processed_path ) - string_length( platformsuffix[i] ) ] = 0; break; } } for( i = 0; i < 1; ++i ) { if( string_ends_with( exe_processed_path, binsuffix[i] ) ) { exe_processed_path[ string_length( exe_processed_path ) - string_length( binsuffix[i] ) ] = 0; break; } } exe_processed_path = path_append( exe_processed_path, "config" ); abs_exe_processed_path = path_make_absolute( exe_processed_path ); paths[0] = environment_executable_directory(); paths[1] = sub_exe_path; paths[2] = abs_exe_parent_path; paths[3] = abs_exe_processed_path; #if FOUNDATION_PLATFORM_FAMILY_DESKTOP && !BUILD_DEPLOY paths[4] = environment_initial_working_directory(); #else paths[4] = 0; #endif #if FOUNDATION_PLATFORM_APPLE bundle_path = path_merge( environment_executable_directory(), "../Resources/config" ); paths[5] = bundle_path; #elif FOUNDATION_PLATFORM_ANDROID paths[5] = "/config"; #else paths[5] = 0; #endif #if FOUNDATION_PLATFORM_FAMILY_DESKTOP paths[6] = environment_current_working_directory(); #else paths[6] = 0; #endif paths[7] = 0; paths[8] = 0; string_deallocate( exe_parent_path ); string_deallocate( exe_processed_path ); #if FOUNDATION_PLATFORM_FAMILY_DESKTOP cwd_config_path = path_merge( environment_current_working_directory(), "config" ); paths[7] = cwd_config_path; cmd_line = environment_command_line(); /*lint -e{850} We modify loop var to skip extra arg */ for( icl = 0, clsize = array_size( cmd_line ); icl < clsize; ++icl ) { /*lint -e{613} array_size( cmd_line ) in loop condition does the null pointer guard */ if( string_equal_substr( cmd_line[icl], "--configdir", 11 ) ) { if( string_equal_substr( cmd_line[icl], "--configdir=", 12 ) ) { paths[8] = cmdline_path = string_substr( cmd_line[icl], 12, STRING_NPOS ); } else if( icl < ( clsize - 1 ) ) { paths[8] = cmdline_path = string_clone( cmd_line[++icl] ); } } } #endif start_path = 0; if( !built_in ) { #if FOUNDATION_PLATFORM_WINDOWS home_dir = path_merge( environment_home_directory(), environment_application()->config_dir ); #elif FOUNDATION_PLATFORM_LINUX || FOUNDATION_PLATFORM_MACOSX home_dir = path_prepend( string_concat( ".", environment_application()->config_dir ), environment_home_directory() ); #endif if( home_dir ) paths[9] = home_dir; start_path = 9; } else { paths[9] = 0; } for( i = start_path; i < NUM_SEARCH_PATHS; ++i ) { char* filename; stream_t* istream; bool path_already_searched = false; if( !paths[i] ) continue; for( j = start_path; j < i; ++j ) { if( paths[j] && string_equal( paths[j], paths[i] ) ) { path_already_searched = true; break; } } if( path_already_searched ) continue; //TODO: Support loading configs from virtual file system (i.e in zip/other packages) filename = string_append( path_merge( paths[i], name ), ".ini" ); istream = 0; #if FOUNDATION_PLATFORM_ANDROID if( i == ANDROID_ASSET_PATH_INDEX ) istream = asset_stream_open( filename, STREAM_IN ); else #endif istream = stream_open( filename, STREAM_IN ); if( istream ) { config_parse( istream, filter_section, overwrite ); stream_deallocate( istream ); } string_deallocate( filename ); if( built_in ) { const char* FOUNDATION_PLATFORM_name = #if FOUNDATION_PLATFORM_WINDOWS "windows"; #elif FOUNDATION_PLATFORM_LINUX_RASPBERRYPI "raspberrypi"; #elif FOUNDATION_PLATFORM_LINUX "linux"; #elif FOUNDATION_PLATFORM_MACOSX "osx"; #elif FOUNDATION_PLATFORM_IOS "ios"; #elif FOUNDATION_PLATFORM_ANDROID "android"; #else # error Insert platform name "unknown"; #endif filename = string_append( path_append( path_merge( paths[i], FOUNDATION_PLATFORM_name ), name ), ".ini" ); #if FOUNDATION_PLATFORM_ANDROID if( i == ANDROID_ASSET_PATH_INDEX ) istream = asset_stream_open( filename, STREAM_IN ); else #endif istream = stream_open( filename, STREAM_IN ); if( istream ) { config_parse( istream, filter_section, overwrite ); stream_deallocate( istream ); } string_deallocate( filename ); } } string_deallocate( home_dir ); string_deallocate( cmdline_path ); string_deallocate( sub_exe_path ); string_deallocate( abs_exe_processed_path ); string_deallocate( abs_exe_parent_path ); string_deallocate( bundle_path ); string_deallocate( cwd_config_path ); }
int main_initialize(void) { foundation_config_t config; application_t application; int ret; size_t iarg, asize; const string_const_t* cmdline = environment_command_line(); _test_memory_tracker = true; for (iarg = 0, asize = array_size(cmdline); iarg < asize; ++iarg) { if (string_equal(STRING_ARGS(cmdline[iarg]), STRING_CONST("--no-memory-tracker"))) _test_memory_tracker = false; } if (_test_memory_tracker) memory_set_tracker(memory_tracker_local()); memset(&config, 0, sizeof(config)); #if BUILD_MONOLITHIC //For fs monitor test config.fs_monitor_max = 1; //For temporary allocator test, 256KiB config.temporary_memory = 256 * 1024; //For testing static hash store config.hash_store_size = 32 * 1024; //Test preallocation of random state buffers config.random_state_prealloc = 4; #endif memset(&application, 0, sizeof(application)); application.name = string_const(STRING_CONST("Foundation library test suite")); application.short_name = string_const(STRING_CONST("test_all")); application.company = string_const(STRING_CONST("Rampant Pixels")); application.version = foundation_version(); application.flags = APPLICATION_UTILITY; application.exception_handler = test_exception_handler; log_set_suppress(0, ERRORLEVEL_INFO); #if (FOUNDATION_PLATFORM_IOS || FOUNDATION_PLATFORM_ANDROID) && BUILD_ENABLE_LOG log_set_handler(test_log_handler); #endif #if !FOUNDATION_PLATFORM_IOS && !FOUNDATION_PLATFORM_ANDROID && !FOUNDATION_PLATFORM_PNACL _test_should_start = true; #endif ret = foundation_initialize(memory_system_malloc(), application, config); #if BUILD_MONOLITHIC //For monolithic process test if (string_array_find(cmdline, array_size(cmdline), STRING_CONST("wait for kill")) >= 0) { while (true) thread_sleep(100); } test_set_suitable_working_directory(); #endif return ret; }