static void* stream_blocking_thread(void* arg) { int iloop; socket_t* sock = (socket_t*)arg; char buffer_out[317] = {0}; char buffer_in[317] = {0}; stream_t* stream = socket_stream(sock); for (iloop = 0; !thread_try_wait(0) && iloop < 512; ++iloop) { log_infof(HASH_NETWORK, STRING_CONST("UDP write pass %d"), iloop); EXPECT_SIZEEQ(stream_write(stream, buffer_out, 127), 127); EXPECT_SIZEEQ(stream_write(stream, buffer_out + 127, 180), 180); stream_flush(stream); EXPECT_SIZEEQ(stream_write(stream, buffer_out + 307, 10), 10); stream_flush(stream); log_infof(HASH_NETWORK, STRING_CONST("UDP read pass %d"), iloop); EXPECT_SIZEEQ(stream_read(stream, buffer_in, 235), 235); EXPECT_SIZEEQ(stream_read(stream, buffer_in + 235, 82), 82); thread_yield(); } log_debugf(HASH_NETWORK, STRING_CONST("IO complete on socket 0x%llx"), sock); stream_deallocate(stream); return 0; }
static void* datagram_client_blocking_thread(void* arg) { int iloop; test_datagram_arg_t* darg = arg; socket_t* sock = darg->sock; network_address_t* target = darg->target; const network_address_t* address; char buffer[1024] = {0}; size_t send = 973; size_t recv; log_debugf(HASH_NETWORK, STRING_CONST("IO start on socket 0x%llx"), sock); for (iloop = 0; iloop < 512; ++iloop) { log_infof(HASH_NETWORK, STRING_CONST("UDP read/write pass %d"), iloop); EXPECT_EQ(udp_socket_sendto(sock, buffer, send, target), send); recv = udp_socket_recvfrom(sock, buffer, send, &address); EXPECT_EQ(recv, send); EXPECT_TRUE(network_address_equal(target, address)); thread_yield(); } log_infof(HASH_NETWORK, STRING_CONST("IO complete on socket 0x%llx"), sock); return 0; }
static void test_run( void ) { unsigned int ig, gsize, ic, csize; void* result = 0; #if !BUILD_MONOLITHIC object_t thread_event = 0; #endif log_infof( HASH_TEST, "Running test suite: %s", test_suite.application().short_name ); _test_failed = false; #if !BUILD_MONOLITHIC thread_event = thread_create( test_event_thread, "event_thread", THREAD_PRIORITY_NORMAL, 0 ); thread_start( thread_event, 0 ); while( !thread_is_running( thread_event ) ) thread_yield(); #endif for( ig = 0, gsize = array_size( _test_groups ); ig < gsize; ++ig ) { log_infof( HASH_TEST, "Running tests from group %s", _test_groups[ig]->name ); for( ic = 0, csize = array_size( _test_groups[ig]->cases ); ic < csize; ++ic ) { log_infof( HASH_TEST, " Running %s tests", _test_groups[ig]->cases[ic]->name ); result = _test_groups[ig]->cases[ic]->fn(); if( result != 0 ) { log_warn( HASH_TEST, WARNING_SUSPICIOUS, " FAILED" ); _test_failed = true; } else { log_info( HASH_TEST, " PASSED" ); } #if BUILD_MONOLITHIC if( _test_should_terminate ) { _test_failed = true; goto exit; } #endif } } #if !BUILD_MONOLITHIC thread_terminate( thread_event ); thread_destroy( thread_event ); while( thread_is_running( thread_event ) || thread_is_thread( thread_event ) ) thread_yield(); #else exit: #endif log_infof( HASH_TEST, "Finished test suite: %s", test_suite.application().short_name ); }
void Resources::Init() { char buf[PATH_MAX]; if( osx_get_resource_path(buf,PATH_MAX) ) { s_ResourcePath = JoinPath(buf,"data"); log_infof("data: %s\n", s_ResourcePath.c_str()); } else { log_infof("couldn't get path for data\n"); // uhoh... s_ResourcePath = "./data"; } }
static BOOL STDCALL _main_console_handler(DWORD control_type) { const char* control_name = "UNKNOWN"; bool post_terminate = false; bool handled = true; switch (control_type) { case CTRL_C_EVENT: control_name = "CTRL_C"; post_terminate = true; break; case CTRL_BREAK_EVENT: control_name = "CTRL_BREAK"; break; case CTRL_CLOSE_EVENT: control_name = "CTRL_CLOSE"; post_terminate = true; break; case CTRL_LOGOFF_EVENT: control_name = "CTRL_LOGOFF"; post_terminate = !config_bool(HASH_APPLICATION, HASH_DAEMON); break; case CTRL_SHUTDOWN_EVENT: control_name = "CTRL_SHUTDOWN"; post_terminate = true; break; default: handled = false; break; } log_infof(0, STRING_CONST("Caught console control: %s (%d)"), control_name, control_type); if (post_terminate) { /*lint -e{970} */ unsigned long level = 0, flags = 0; system_post_event(FOUNDATIONEVENT_TERMINATE); GetProcessShutdownParameters(&level, &flags); SetProcessShutdownParameters(level, SHUTDOWN_NORETRY); thread_sleep(1000); } return handled; }
int hashify_write_file(stream_t* generated_file, string_t output_filename) { bool need_update = false; stream_t* output_file = 0; int result = HASHIFY_RESULT_OK; output_file = stream_open(STRING_ARGS(output_filename), STREAM_OUT | STREAM_IN); if (!output_file) { need_update = true; output_file = stream_open(STRING_ARGS(output_filename), STREAM_OUT); if (!output_file) { log_warnf(0, WARNING_INVALID_VALUE, STRING_CONST("Unable to open output file: %.*s"), STRING_FORMAT(output_filename)); return HASHIFY_RESULT_MISSING_OUTPUT_FILE; } } if (!need_update) need_update = !uint128_equal(stream_md5(generated_file), stream_md5(output_file)); if (need_update) { char local_buffer[1024]; size_t read = 0; size_t written = 0; uint64_t total_written = 0; stream_seek(generated_file, 0, STREAM_SEEK_BEGIN); stream_seek(output_file, 0, STREAM_SEEK_BEGIN); while (!stream_eos(generated_file)) { read = stream_read(generated_file, local_buffer, 1024); if (!read) break; written = stream_write(output_file, local_buffer, read); total_written += written; if (written != read) { log_errorf(0, ERROR_SYSTEM_CALL_FAIL, STRING_CONST("Unable to write to output file '%.*s': %" PRIsize " of %" PRIsize " bytes written"), STRING_FORMAT(output_filename), written, read); result = HASHIFY_RESULT_OUTPUT_FILE_WRITE_FAIL; break; } } if (result == HASHIFY_RESULT_OK) { stream_truncate(output_file, (size_t)total_written); log_infof(0, STRING_CONST(" wrote %.*s : %" PRIu64 " bytes"), STRING_FORMAT(output_filename), total_written); } } else { log_info(0, STRING_CONST(" hash file already up to date")); } stream_deallocate(output_file); return result; }
void config_parse_commandline( const char* const* cmdline, unsigned int num ) { //TODO: Implement, format --section:key=value unsigned int arg; for( arg = 0; arg < num; ++arg ) { if( string_match_pattern( cmdline[arg], "--*:*=*" ) ) { unsigned int first_sep = string_find( cmdline[arg], ':', 0 ); unsigned int second_sep = string_find( cmdline[arg], '=', 0 ); if( ( first_sep != STRING_NPOS ) && ( second_sep != STRING_NPOS ) && ( first_sep < second_sep ) ) { unsigned int section_length = first_sep - 2; unsigned int end_pos = first_sep + 1; unsigned int key_length = second_sep - end_pos; const char* section_str = cmdline[arg] + 2; const char* key_str = pointer_offset_const( cmdline[arg], end_pos ); hash_t section = hash( section_str, section_length ); hash_t key = hash( key_str, key_length ); char* value = string_substr( cmdline[arg], second_sep + 1, STRING_NPOS ); char* set_value = value; unsigned int value_length = string_length( value ); if( !value_length ) config_set_string( section, key, "" ); else if( string_equal( value, "false" ) ) config_set_bool( section, key, false ); else if( string_equal( value, "true" ) ) config_set_bool( section, key, true ); else if( ( string_find( value, '.', 0 ) != STRING_NPOS ) && ( string_find_first_not_of( value, "0123456789.", 0 ) == STRING_NPOS ) && ( string_find( value, '.', string_find( value, '.', 0 ) + 1 ) == STRING_NPOS ) ) //Exactly one "." config_set_real( section, key, string_to_real( value ) ); else if( string_find_first_not_of( value, "0123456789", 0 ) == STRING_NPOS ) config_set_int( section, key, string_to_int64( value ) ); else { if( ( value_length > 1 ) && ( value[0] == '"' ) && ( value[ value_length - 1 ] == '"' ) ) { value[ value_length - 1 ] = 0; set_value = value + 1; config_set_string( section, key, set_value ); } else { config_set_string( section, key, value ); } } log_infof( HASH_CONFIG, "Config value from command line: %.*s:%.*s = %s", section_length, section_str, key_length, key_str, set_value ); string_deallocate( value ); } } } }
static void test_local_exception_handler(const char* dump_path, size_t length) { FOUNDATION_UNUSED(dump_path); #if !BUILD_ENABLE_LOG FOUNDATION_UNUSED(length); #endif log_infof(HASH_TEST, STRING_CONST("Exception handler called: %.*s"), (int)length, dump_path); _exception_handler_called = true; }
int hashify_process_strings(string_t* strings) { size_t istr, strings_size; for (istr = 0, strings_size = array_size(strings); istr < strings_size; ++istr) { uint64_t hash_value = hash(STRING_ARGS(strings[istr])); log_infof(0, STRING_CONST("String '%.*s' hash: 0x%" PRIx64), STRING_FORMAT(strings[istr]), hash_value); } return 0; }
int hashify_process_strings( const char* const* strings ) { int istr, strings_size; for( istr = 0, strings_size = array_size( strings ); istr < strings_size; ++istr ) { uint64_t hash_value = hash( strings[istr], string_length( strings[istr] ) ); log_infof( "String '%s' hash: 0x%llx", strings[istr], hash_value ); } return 0; }
static void* datagram_server_blocking_thread(void* arg) { int iloop; const network_address_t* from; socket_t* sock = (socket_t*)arg; char buffer[1024]; for (iloop = 0; iloop < 512 * 4; ++iloop) { log_infof(HASH_NETWORK, STRING_CONST("UDP mirror pass %d"), iloop); size_t read = udp_socket_recvfrom(sock, buffer, sizeof(buffer), &from); EXPECT_EQ(read, 973); EXPECT_EQ(udp_socket_sendto(sock, buffer, read, from), read); thread_yield(); } log_infof(HASH_NETWORK, STRING_CONST("IO complete on socket 0x%llx"), sock); return 0; }
static void* event_thread( object_t thread, void* arg ) { event_block_t* block; event_t* event = 0; while( !thread_should_terminate( thread ) ) { block = event_stream_process( system_event_stream() ); event = 0; while( ( event = event_next( block, event ) ) ) { switch( event->id ) { case FOUNDATIONEVENT_START: #if FOUNDATION_PLATFORM_IOS || FOUNDATION_PLATFORM_IOS log_infof( HASH_TEST, "Application start event received" ); _test_should_start = true; #endif break; case FOUNDATIONEVENT_TERMINATE: #if FOUNDATION_PLATFORM_IOS || FOUNDATION_PLATFORM_IOS log_infof( HASH_TEST, "Application terminate event received" ); _test_should_terminate = true; #else log_warn( HASH_TEST, WARNING_SUSPICIOUS, "Terminating tests due to event" ); process_exit( -2 ); #endif break; default: break; } } thread_sleep( 10 ); } return 0; }
int bin2hex_process_files( char const* const* input, char const* const* output, int columns ) { int result = BIN2HEX_RESULT_OK; unsigned int ifile, files_size; for( ifile = 0, files_size = array_size( input ); ( result == BIN2HEX_RESULT_OK ) && ( ifile < files_size ); ++ifile ) { char* input_filename = 0; char* output_filename = 0; stream_t* input_file = 0; stream_t* output_file = 0; input_filename = path_clean( string_clone( input[ifile] ), path_is_absolute( input[ifile] ) ); error_context_push( "parsing file", input_filename ); output_filename = path_clean( string_clone( output[ifile] ), path_is_absolute( output[ifile] ) ); log_infof( 0, "bin2hex %s -> %s", input_filename, output_filename ); input_file = stream_open( input_filename, STREAM_IN | STREAM_BINARY ); if( !input_file ) { log_warnf( 0, WARNING_BAD_DATA, "Unable to open input file: %s", input_filename ); result = BIN2HEX_RESULT_MISSING_INPUT_FILE; } else { output_file = stream_open( output_filename, STREAM_OUT ); if( !output_file ) { log_warnf( 0, WARNING_BAD_DATA, "Unable to open output file: %s", output_filename ); result = BIN2HEX_RESULT_UNABLE_TO_OPEN_OUTPUT_FILE; } } if( input_file && output_file ) result = bin2hex_process_file( input_file, output_file, columns ); stream_deallocate( input_file ); stream_deallocate( output_file ); string_deallocate( output_filename ); error_context_pop(); string_deallocate( input_filename ); } if( ( result == BIN2HEX_RESULT_OK ) && ( files_size > 0 ) ) log_info( 0, "All files generated" ); return result; }
void sink_manager_print_sinks() { uint64_t now = util_time_now(); if (list.nbr_sinks > 0) { log_info("Alive sinks:"); } for (int i = 0; i < list.nbr_sinks; i++) { log_infof(" %s - last heartbeast %lus ago", inet_ntoa(list.sinks[i].ip), (now - list.sinks[i].last_heartbeat) / 1000); } }
static void sighandler(int sig) { const char* signame = "UNKNOWN"; switch (sig) { case SIGKILL: signame = "SIGKILL"; break; case SIGTERM: signame = "SIGTERM"; break; case SIGQUIT: signame = "SIGQUIT"; break; case SIGINT: signame = "SIGINT"; break; default: break; } log_infof(0, STRING_CONST("Caught signal: %s (%d)"), signame, sig); system_post_event(FOUNDATIONEVENT_TERMINATE); }
static void* test_runner(void* arg) { test_run_fn* tests = (test_run_fn*)arg; int test_fn = 0; int process_result = 0; while (tests[test_fn] && (process_result >= 0)) { if ((process_result = tests[test_fn]()) >= 0) log_infof(HASH_TEST, STRING_CONST("All tests passed (%d)"), process_result); ++test_fn; } return (void*)(intptr_t)process_result; }
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) { const char element[4][2] = { "X", "Y", "Z", "W" }; FOUNDATION_UNUSED(main_arg); log_set_suppress(HASH_TOOL, ERRORLEVEL_DEBUG); log_info(HASH_TOOL, STRING_CONST( "/* mask.h - Vector library - Public Domain - 2013 Mattias Jansson / Rampant Pixels\n" " *\n" " * This library provides a cross-platform vector math library in C11 providing basic support data types and\n" " * functions to write applications and games in a platform-independent fashion. The latest source code is\n" " * always available at\n" " *\n" " * https://github.com/rampantpixels/vector_lib\n" " *\n" " * This library is built on top of the foundation library available at\n" " *\n" " * https://github.com/rampantpixels/foundation_lib\n" " *\n" " * This library is put in the public domain; you can redistribute it and/or modify it without any restrictions.\n" " *\n" "*/\n\n" "#pragma once\n\n" "/*! \\file math/mask.h\n" " Vector mask definitions */\n\n" "#include <vector/types.h>\n\n" "#define VECTOR_MASK(x, y, z, w) (((w) << 6) | ((z) << 4) | ((y) << 2) | ((x)))\n\n" "/* Vector shuffle masks where the operation performed by\n" " v1 = vector_shuffle(v0, VECTOR_MASK_abcd)\n" " will be equal to\n" " v1.x = v0[a]\n" " v1.y = v0[b]\n" " v1.z = v0[c]\n" " v1.w = v0[d] */\n")); for (int e0 = 0; e0 < 4; ++e0) for (int e1 = 0; e1 < 4; ++e1) for (int e2 = 0; e2 < 4; ++e2) for (int e3 = 0; e3 < 4; ++e3) log_infof(HASH_TOOL, STRING_CONST("#define VECTOR_MASK_%s%s%s%s VECTOR_MASK(%d, %d, %d, %d)"), element[e0], element[e1], element[e2], element[e3], e0, e1, e2, e3); return 0; }
static void add_sink(sink_t sink) { log_infof("Adding new sink: %s", inet_ntoa(sink.ip)); pthread_mutex_lock(&w_mutex); if (list.nbr_sinks < list.nbr_sinks_allocated) { list.sinks[list.nbr_sinks++] = sink; } else { uint32_t new_sink_space = list.nbr_sinks_allocated * 2; log_infof("List of sinks is full, growing list to have space for %u entries.", new_sink_space); list.sinks = realloc(list.sinks, new_sink_space); if (list.sinks == NULL) { DIE("Unable to allocate more space for sinks"); } list.sinks[list.nbr_sinks++] = sink; } pthread_mutex_unlock(&w_mutex); sink_manager_print_sinks(); }
static void* test_runner( object_t obj, void* arg ) { FOUNDATION_UNUSED( obj ); test_run_fn* tests = (test_run_fn*)arg; int test_fn = 0; int process_result = 0; while( tests[test_fn] && ( process_result >= 0 ) ) { if( ( process_result = tests[test_fn]() ) >= 0 ) log_infof( HASH_TEST, "All tests passed (%d)", process_result ); ++test_fn; } return (void*)(intptr_t)process_result; }
static int blast_client_send_handshake(blast_client_t* client, blast_reader_t* reader) { int iaddr, addrsize = 0; socket_t** socks; const network_address_t** addrarr; packet_handshake_t packet; packet.type = PACKET_HANDSHAKE; packet.token = 0; packet.timestamp = blast_timestamp(client->begin_send); packet.datasize = reader->size; packet.seq = blast_seq(client->seq++); packet.namesize = (uint32_t)string_copy(packet.name, sizeof(packet.name), STRING_ARGS(reader->name)).length; if (client->target) { addrarr = &client->target; socks = &client->sock; addrsize = 1; } else { addrarr = (const network_address_t**)client->address; socks = client->socks; addrsize = array_size(addrarr); } for (iaddr = 0; iaddr < addrsize; ++iaddr) { udp_socket_sendto(socks[iaddr], &packet, sizeof(packet_handshake_t) - (PACKET_NAME_MAXSIZE - packet.namesize) + 1, addrarr[iaddr]); #if BUILD_ENABLE_LOG { char buffer[NETWORK_ADDRESS_NUMERIC_MAX_LENGTH]; string_t addr = network_address_to_string(buffer, sizeof(buffer), addrarr[iaddr], true); log_infof(HASH_BLAST, STRING_CONST("Sent handshake to %.*s (seq %lld, timestamp %lld)"), STRING_FORMAT(addr), packet.seq, (tick_t)packet.timestamp); } #endif } client->last_send = time_current(); return 0; }
static void blast_client_report_progress(blast_client_t* client, bool force) { int progress = (int)((real)((float64_t)((client->seq - array_size(client->pending)) * PACKET_CHUNK_SIZE) / (float64_t)client->readers[client->current]->size) * REAL_C(100.0)); if (force || (progress > (client->last_progress_percent + 5)) || (time_elapsed(client->last_progress) > 1.0f)) { if (client->packets_sent > 0) { real resend_rate = (real)((float64_t)client->packets_resent / (float64_t)client->packets_sent) * REAL_C(100.0); log_infof(HASH_BLAST, STRING_CONST("Progress: %.*s %d%% (resend rate %.2" PRIreal "%% %lld/%lld))"), STRING_FORMAT(client->readers[client->current]->name), progress, resend_rate, client->packets_resent, client->packets_sent); } client->last_progress = time_current(); client->last_progress_percent = progress; } }
bool system_message_box( const char* title, const char* message, bool cancel_button ) { log_infof( "%s\n\n%s", title, message ); if( environment_application()->flags & APPLICATION_UTILITY ) return true; #if FOUNDATION_PLATFORM_WINDOWS return ( MessageBoxA( 0, message, title, cancel_button ? MB_OKCANCEL : MB_OK ) == IDOK ); #elif FOUNDATION_PLATFORM_APPLE return _system_show_alert( title, message, cancel_button ? 1 : 0 ) > 0; #elif 0//FOUNDATION_PLATFORM_LINUX char* buf = string_format( "%s\n\n%s\n", title, message ); pid_t pid = fork(); switch( pid ) { case -1: //error string_deallocate( buf ); break; case 0: execlp( "xmessage", "xmessage", "-buttons", cancel_button ? "OK:101,Cancel:102" : "OK:101", "-default", "OK", "-center", buf, (char*)0 ); _exit( -1 ); break; default: { string_deallocate( buf ); int status; waitpid( pid, &status, 0 ); if( ( !WIFEXITED( status ) ) || ( WEXITSTATUS( status ) != 101 ) ) return false; return true; } } return false; #else //Not implemented return false; #endif }
static void purge_dead_sinks() { uint64_t now = util_time_now(); uint8_t purged_sinks = 0; for (int i = 0; i < list.nbr_sinks; i++) { if (now - list.sinks[i].last_heartbeat > (SINK_MANAGER_SINK_TIMEOUT * 1000)) { if (purged_sinks == 0) { log_info("Purge sinks:"); } log_infof(" %s - timed out. Uncontacted for %lus", inet_ntoa(list.sinks[i].ip), (now - list.sinks[i].last_heartbeat) / 1000); remove_sink(i); purged_sinks++; } } }
static uint32_t _system_user_locale( void ) { fnGetLocaleInfoEx get_locale_info = (fnGetLocaleInfoEx)GetProcAddress( GetModuleHandleA( "kernel32.dll" ), "GetLocaleInfoEx" ); if( get_locale_info ) { wchar_t locale_sname[128] = {0}; char locale_string[8] = {0}; get_locale_info( LOCALE_NAME_USER_DEFAULT, LOCALE_SNAME, locale_sname, 32 ); string_convert_utf16( locale_string, (uint16_t*)locale_sname, 8, (unsigned int)wcslen( locale_sname ) ); locale_string[5] = 0; if( string_match_pattern( locale_string, "??" "-" "??" ) ) { locale_string[2] = locale_string[3]; locale_string[3] = locale_string[4]; locale_string[4] = 0; log_infof( "User default locale: %s", locale_string ); return *(uint32_t*)locale_string; } } return _system_default_locale(); }
static void* test_runner(void* arg) { test_run_fn* tests = (test_run_fn*)arg; int process_result = 0; size_t itest, numtests; for (numtests = 0; tests[numtests];) ++numtests; itest = 0; while (tests[itest] && (process_result >= 0)) { #if (FOUNDATION_PLATFORM_IOS || FOUNDATION_PLATFORM_ANDROID) && !BUILD_ENABLE_LOG { char buffer[64]; string_t msg = string_format(buffer, sizeof(buffer), STRING_CONST("Test %" PRIsize "/%" PRIsize " starting... "), itest+1, numtests); test_log_view_append(STRING_ARGS(msg)); } #endif if ((process_result = tests[itest]()) >= 0) { log_infof(HASH_TEST, STRING_CONST("Test %" PRIsize "/%" PRIsize " passed (%d)"), itest+1, numtests, process_result); #if (FOUNDATION_PLATFORM_IOS || FOUNDATION_PLATFORM_ANDROID) && !BUILD_ENABLE_LOG test_log_view_append(STRING_CONST("PASSED\n")); #endif } #if (FOUNDATION_PLATFORM_IOS || FOUNDATION_PLATFORM_ANDROID) && !BUILD_ENABLE_LOG else { test_log_view_append(STRING_CONST("FAILED\n")); } #endif ++itest; } return (void*)(intptr_t)process_result; }
DECLARE_TEST( stacktrace, resolve ) { #define TEST_DEPTH 64 void* trace[TEST_DEPTH]; unsigned int num_frames = 0; char* resolved = 0; num_frames = stacktrace_capture( trace, TEST_DEPTH, 0 ); EXPECT_GT( num_frames, 3 ); resolved = stacktrace_resolve( trace, num_frames, 0 ); EXPECT_NE( resolved, 0 ); log_infof( HASH_TEST, "Resolved stack trace:\n%s", resolved ); EXPECT_NE( string_find_string( resolved, "stacktraceresolve_fn", 0 ), STRING_NPOS ); EXPECT_NE( string_find_string( resolved, "test_run", 0 ), STRING_NPOS ); //EXPECT_NE( string_find_string( resolved, "main_run", 0 ), STRING_NPOS ); memory_deallocate( resolved ); return 0; }
static int render_import_glsl_shader(stream_t* stream, const uuid_t uuid, const char* type, size_t type_length) { resource_source_t source; void* blob = 0; size_t size; size_t read; size_t begin; size_t next; hash_t checksum; tick_t timestamp; uint64_t platform; size_t maxtokens; size_t parameter; string_const_t* token = 0; string_const_t valstr; char buffer[128]; int ret = 0; resource_platform_t platformdecl = { -1, -1, RENDERAPIGROUP_OPENGL, -1, -1, -1}; resource_source_initialize(&source); resource_source_read(&source, uuid); read = 0; size = stream_size(stream); blob = memory_allocate(HASH_RESOURCE, size, 0, MEMORY_PERSISTENT); size = stream_read(stream, blob, size); platform = resource_platform(platformdecl); timestamp = time_system(); checksum = hash(blob, size); if (resource_source_write_blob(uuid, timestamp, HASH_SOURCE, platform, checksum, blob, size)) { resource_source_set_blob(&source, timestamp, HASH_SOURCE, platform, checksum, size); } else { ret = -1; goto finalize; } //Parse source and set parameters maxtokens = 256; token = memory_allocate(HASH_RESOURCE, sizeof(string_const_t) * maxtokens, 0, MEMORY_PERSISTENT); begin = 0; parameter = 0; do { string_const_t tokens[64], line; size_t itok, ntokens; next = string_find_first_of(blob, size, STRING_CONST("\n\r"), begin); line = string_substr(blob, size, begin, next - begin); ntokens = string_explode(STRING_ARGS(line), STRING_CONST(GLSL_TOKEN_DELIM), tokens, maxtokens, false); for (itok = 0; itok < ntokens; ++itok) { if ((string_equal(STRING_ARGS(tokens[itok]), STRING_CONST("attribute")) || string_equal(STRING_ARGS(tokens[itok]), STRING_CONST("uniform"))) && (itok + 2 < ntokens)) { char typebuf[16], dimbuf[16]; string_const_t typestr = tokens[itok + 1]; string_const_t namestr = tokens[itok + 2]; string_const_t dimstr; int parameter_type = glsl_type_to_parameter_type(typestr); if (parameter_type < 0) continue; int parameter_dim = glsl_dim_from_token(typestr); if (parameter_dim == 1) parameter_dim = glsl_dim_from_token(namestr); namestr = glsl_name_from_token(namestr); typestr = string_to_const(string_from_uint(typebuf, sizeof(typebuf), (unsigned int)parameter_type, false, 0, 0)); dimstr = string_to_const(string_from_uint(dimbuf, sizeof(dimbuf), (unsigned int)parameter_dim, false, 0, 0)); log_debugf(HASH_RESOURCE, STRING_CONST("parameter: %.*s type %.*s dim %.*s"), STRING_FORMAT(namestr), STRING_FORMAT(typestr), STRING_FORMAT(dimstr)); string_t param = string_format(buffer, sizeof(buffer), STRING_CONST("parameter_type_%" PRIsize), parameter); resource_source_set(&source, timestamp, hash(STRING_ARGS(param)), platform, STRING_ARGS(typestr)); param = string_format(buffer, sizeof(buffer), STRING_CONST("parameter_name_%" PRIsize), parameter); resource_source_set(&source, timestamp, hash(STRING_ARGS(param)), platform, STRING_ARGS(namestr)); param = string_format(buffer, sizeof(buffer), STRING_CONST("parameter_dim_%" PRIsize), parameter); resource_source_set(&source, timestamp, hash(STRING_ARGS(param)), platform, STRING_ARGS(dimstr)); ++parameter; } } begin = string_find_first_not_of(blob, size, STRING_CONST(STRING_WHITESPACE), next); } while (next != STRING_NPOS); valstr = string_from_uint_static(parameter, false, 0, 0); resource_source_set(&source, timestamp, HASH_PARAMETER_COUNT, platform, STRING_ARGS(valstr)); resource_source_set(&source, timestamp, HASH_RESOURCE_TYPE, 0, type, type_length); if (!resource_source_write(&source, uuid, false)) { string_const_t uuidstr = string_from_uuid_static(uuid); log_warnf(HASH_RESOURCE, WARNING_SUSPICIOUS, STRING_CONST("Failed writing imported GLSL shader: %.*s"), STRING_FORMAT(uuidstr)); ret = -1; goto finalize; } else { string_const_t uuidstr = string_from_uuid_static(uuid); log_infof(HASH_RESOURCE, STRING_CONST("Wrote imported GLSL shader: %.*s"), STRING_FORMAT(uuidstr)); } finalize: memory_deallocate(blob); memory_deallocate(token); resource_source_finalize(&source); return ret; }
static int render_import_program(stream_t* stream, const uuid_t uuid) { char buffer[1024]; char pathbuf[BUILD_MAX_PATHLEN]; resource_source_t source; resource_platform_t platformdecl = {-1, -1, -1, -1, -1, -1}; uint64_t platform; tick_t timestamp; int ret = 0; resource_source_initialize(&source); resource_source_read(&source, uuid); platform = resource_platform(platformdecl); timestamp = time_system(); while (!stream_eos(stream)) { string_const_t type, ref; string_const_t fullpath; string_const_t uuidstr; uuid_t shaderuuid; hash_t typehash; string_t line = stream_read_line_buffer(stream, buffer, sizeof(buffer), '\n'); string_split(STRING_ARGS(line), STRING_CONST(" \t"), &type, &ref, false); type = string_strip(STRING_ARGS(type), STRING_CONST(STRING_WHITESPACE)); ref = string_strip(STRING_ARGS(ref), STRING_CONST(STRING_WHITESPACE)); if (!type.length || !ref.length) continue; typehash = hash(STRING_ARGS(type)); if ((typehash != HASH_VERTEXSHADER) && (typehash != HASH_PIXELSHADER)) { log_warnf(HASH_RESOURCE, WARNING_SUSPICIOUS, STRING_CONST("Ignore invalid line: %.*s"), STRING_FORMAT(line)); continue; } shaderuuid = string_to_uuid(STRING_ARGS(ref)); if (uuid_is_null(shaderuuid)) { if (path_is_absolute(STRING_ARGS(ref))) { fullpath = ref; } else { string_t full; string_const_t path = stream_path(stream); path = path_directory_name(STRING_ARGS(path)); full = path_concat(pathbuf, sizeof(pathbuf), STRING_ARGS(path), STRING_ARGS(ref)); full = path_absolute(STRING_ARGS(full), sizeof(pathbuf)); fullpath = string_const(STRING_ARGS(full)); } resource_signature_t sig = resource_import_lookup(STRING_ARGS(fullpath)); if (uuid_is_null(sig.uuid)) { if (!resource_import(STRING_ARGS(fullpath), uuid_null())) { log_warnf(HASH_RESOURCE, WARNING_SUSPICIOUS, STRING_CONST("Unable to import linked shader: %.*s"), STRING_FORMAT(fullpath)); ret = -1; goto finalize; } sig = resource_import_lookup(STRING_ARGS(fullpath)); if (uuid_is_null(sig.uuid)) { log_warnf(HASH_RESOURCE, WARNING_SUSPICIOUS, STRING_CONST("Import linked shader gave no UUID: %.*s"), STRING_FORMAT(fullpath)); ret = -1; goto finalize; } } shaderuuid = sig.uuid; } if (!uuid_is_null(shaderuuid)) { uuidstr = string_from_uuid_static(shaderuuid); resource_source_set(&source, timestamp, typehash, platform, STRING_ARGS(uuidstr)); } } resource_source_set(&source, timestamp, HASH_RESOURCE_TYPE, 0, STRING_CONST("program")); if (!resource_source_write(&source, uuid, false)) { string_const_t uuidstr = string_from_uuid_static(uuid); log_warnf(HASH_RESOURCE, WARNING_SUSPICIOUS, STRING_CONST("Failed writing imported program: %.*s"), STRING_FORMAT(uuidstr)); ret = -1; goto finalize; } else { string_const_t uuidstr = string_from_uuid_static(uuid); log_infof(HASH_RESOURCE, STRING_CONST("Wrote imported program: %.*s"), STRING_FORMAT(uuidstr)); } finalize: resource_source_finalize(&source); return ret; }
static int render_import_shader(stream_t* stream, const uuid_t uuid) { char buffer[1024]; char pathbuf[BUILD_MAX_PATHLEN]; resource_source_t source; resource_platform_t platformdecl = {-1, -1, -1, -1, -1, -1}; uint64_t platform; tick_t timestamp; int ret = 0; resource_source_initialize(&source); resource_source_read(&source, uuid); platform = resource_platform(platformdecl); timestamp = time_system(); while (!stream_eos(stream)) { uuid_t shaderuuid; string_const_t target, ref, fullpath; string_t line = stream_read_line_buffer(stream, buffer, sizeof(buffer), '\n'); string_split(STRING_ARGS(line), STRING_CONST(" \t"), &target, &ref, false); ref = string_strip(STRING_ARGS(ref), STRING_CONST(STRING_WHITESPACE)); shaderuuid = string_to_uuid(STRING_ARGS(ref)); if (uuid_is_null(shaderuuid)) { if (path_is_absolute(STRING_ARGS(ref))) { fullpath = ref; } else { string_t full; string_const_t path = stream_path(stream); path = path_directory_name(STRING_ARGS(path)); full = path_concat(pathbuf, sizeof(pathbuf), STRING_ARGS(path), STRING_ARGS(ref)); full = path_absolute(STRING_ARGS(full), sizeof(pathbuf)); fullpath = string_const(STRING_ARGS(full)); } resource_signature_t sig = resource_import_lookup(STRING_ARGS(fullpath)); if (uuid_is_null(sig.uuid)) { if (!resource_import(STRING_ARGS(fullpath), uuid_null())) { log_warnf(HASH_RESOURCE, WARNING_SUSPICIOUS, STRING_CONST("Unable to import linked shader: %.*s"), STRING_FORMAT(fullpath)); ret = -1; goto finalize; } sig = resource_import_lookup(STRING_ARGS(fullpath)); if (uuid_is_null(sig.uuid)) { log_warnf(HASH_RESOURCE, WARNING_SUSPICIOUS, STRING_CONST("Import linked shader gave no UUID: %.*s"), STRING_FORMAT(fullpath)); ret = -1; goto finalize; } } shaderuuid = sig.uuid; } if (!uuid_is_null(shaderuuid)) { resource_platform_t targetplatformdecl = render_import_parse_target(STRING_ARGS(target), platformdecl); uint64_t targetplatform = resource_platform(targetplatformdecl); if (resource_autoimport_need_update(shaderuuid, targetplatform)) resource_autoimport(shaderuuid); const string_const_t uuidstr = string_from_uuid_static(shaderuuid); resource_source_set(&source, timestamp, HASH_SHADER, targetplatform, STRING_ARGS(uuidstr)); resource_source_set_dependencies(uuid, targetplatform, &shaderuuid, 1); } } resource_source_set(&source, timestamp, HASH_RESOURCE_TYPE, 0, STRING_CONST("shader")); if (!resource_source_write(&source, uuid, false)) { string_const_t uuidstr = string_from_uuid_static(uuid); log_warnf(HASH_RESOURCE, WARNING_SUSPICIOUS, STRING_CONST("Failed writing imported shader: %.*s"), STRING_FORMAT(uuidstr)); ret = -1; goto finalize; } else { string_const_t uuidstr = string_from_uuid_static(uuid); log_infof(HASH_RESOURCE, STRING_CONST("Wrote imported shader: %.*s"), STRING_FORMAT(uuidstr)); } finalize: resource_source_finalize(&source); return 0; }