//gcc --std=c99 -I. -o test -DHAVE_UNISTD_H -DISDK_XATTR_TEST_MAIN isdk_xattr.c sds.c zmalloc.c int main(void) { { int fd = open ("mytestfile", O_WRONLY | O_CREAT | O_NONBLOCK | O_NOCTTY, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); if (fd != -1) close(fd); test_cond("touch('mytestfile')", fd != -1); sds path = sdsnew("mytestfile"), key = sdsnew("mydname"), value = sdsnew("hi world!"); test_cond("SetXattr(mytestfile, mydname, 'hi world!')", SetXattr(path, key, value)== 0); test_cond("IsXattrExists(mytestfile, mydname)", IsXattrExists(path, key)); test_cond("IsXattrExists(mytestfile, notexists)", !IsXattrExists(path, "notexists")); test_cond("IsXattrExists(nosuchmytestfile, notexists)", !IsXattrExists("nosuchmytestfile", "notexists")); sds result = GetXattr(path, key); test_cond("GetXattr(mytestfile, mydname)", result && sdslen(result) == 9 && memcmp(result, "hi world!\0", 10) == 0 ); sdsfree(path); sdsfree(key); sdsfree(value); if (result) sdsfree(result); remove("mytestfile"); } test_report(); return 0; }
test_report benchmark_test_with_external_configuration(std::string test_casename, const std::string function_name, int flag){ std::cout << "test case: " << test_casename << " starts with external configuration" << std::endl; general_configuration ext_conf_file("configuration_"+function_name+".txt"); Overall_Optimisation_Configuration_Settings myConf2(test_casename, ext_conf_file, "reference_point_"+function_name+".txt", "penalty_point_"+function_name+".txt", "lower_bound_"+function_name+".txt", "upper_bound_"+function_name+".txt", "starting_point_"+function_name+".txt", "current_step_"+function_name+".txt"); const unsigned int n_of_variables=myConf2.getExternalConfigurationFile().getVar(); const unsigned int n_of_objectives=myConf2.getExternalConfigurationFile().getObj(); objective_function_formulae obj_function(n_of_objectives); ObjectiveFunctionBasic<double> TS_ObjFunc(myConf2, obj_function); Container2 MTM(n_of_variables, n_of_objectives, "MTM","./memories"); Container2 IM(n_of_variables, n_of_objectives, "IM","./memories"); Container2 HISTORY(n_of_variables, n_of_objectives, "HISTORY","./memories"); STM_Container2 STM(myConf2.getExternalConfigurationFile().getStmSize(), n_of_variables, "STM", "./memories"); LTM_Container2Basic2<double> LTM( n_of_variables , myConf2.getExternalConfigurationFile().getRegions(), myConf2.get_lower_bound(), myConf2.get_upper_bound(),"LTM", "./memories"); std::cout << "Memories done!" << std::endl; TabuSearch TS(myConf2, flag, TS_ObjFunc, MTM, IM, HISTORY, STM, LTM); double hyper_volume_indicator=TS.search2(); return test_report(myConf2.getCaseName(), TS.getDatumPnt(), hyper_volume_indicator) ; }
int main() { test_report(); return 0; }
static test_result c (int cmd, int obj, int expected, UINT8 *p) { int location; int match; test_report ("(%d)%s %d => ", cmd, logic_names_cmd[cmd].name, obj); execute_agi_command (cmd, p); location = object_get_location(obj); test_report ("new location %d", location); if (!(match = (expected == location))) { test_report (" [Expected: %d]", expected); } return match ? TEST_OK : TEST_FAIL; }
static test_result c (int cmd, int expected) { int i; UINT8 p[10]; test_report ("(%d)%s all flags => ", cmd, logic_names_cmd[cmd].name); for (i = 0; i < (MAX_FLAGS * 8); i++) { sprintf (p, "%c", i); execute_agi_command (cmd, p); if (!(expected == getflag(i))) { test_report (" [Expected: %d]", expected); return TEST_FAIL; } } return TEST_OK; }
void coEntryPoint1() { test_report("coEntryPoint1"); while (TRUE) { coValue1++; coValueBoth++; OSSwitchCoroutine(&coOther1, &coOther2); } }
void coEntryPoint2() { test_report("coEntryPoint2"); while (TRUE) { coValue2++; coValueBoth++; OSSwitchCoroutine(&coOther2, &coMain); } }
int main(int argc, const char **argv) { log_init(LOG_DEBUG, NULL); test_repl_parse_master_info(); test_report(); return 0; }
static test_result c (int cmd, char *test, char *res, int expected, UINT8 *p) { char result[MAX_LEN]; int numres; int match; sprintf (result, "%s", agi_sprintf (test)); test_report ("(%d)%s %s = ", cmd, logic_names_cmd[cmd].name, result); execute_agi_command (cmd, p); sprintf (result, "%s", agi_sprintf (res)); test_report ("%s", result); numres = strtoul (result, NULL, 0); if (!(match = (expected == numres))) { test_report (" [Expected: %d]", expected); } return match ? TEST_OK : TEST_FAIL; }
int main(int argc, char **argv) { uint8_t *coStackPtr1 = coStack1 + StackSize - 8; OSInitCoroutine(&coOther1, coEntryPoint1, coStackPtr1); uint8_t *coStackPtr2 = coStack2 + StackSize - 8; OSInitCoroutine(&coOther2, coEntryPoint2, coStackPtr2); test_report("main"); for (int i = 0; i < 5; ++i) { OSSwitchCoroutine(&coMain, &coOther1); } test_report("Returned to coMain"); test_assert(coValue1 == 5); test_assert(coValue2 == 5); test_assert(coValueBoth == 10); return 0; }
int main() { clock_t begin; magic::init(); global_engine = engine::instance(); options::get_option("Wild")->value = 17; uci::silent(true); begin = clock(); test_positions(); double elapsed = (clock() - begin) / (1.0 * CLOCKS_PER_SEC); test_report(elapsed); return (EXIT_SUCCESS); }
int zoneParserTest(int argc, char *argv[]) { if (argc < 4) { fprintf(stderr, "need conf file\n"); exit(1); } test_cond("parse ttl 1", parsetime("2w3d3M2") == 17*(24*3600)+180 + 2); test_cond("parse ttl 2", parsetime("2002112") == 2002112); { char dot_origin[] = "google.com."; char domain[255] = "www.google.com."; abs2lenRelative(domain, dot_origin); test_cond("abs2lenRelative 1", strcmp(domain, "\3www") == 0); strcpy(domain, "aa.bb.google.com."); abs2lenRelative(domain, dot_origin); test_cond("abs2lenRelative 2", strcmp(domain, "\2aa\2bb") == 0); strcpy(domain, "google.com."); abs2lenRelative(domain, dot_origin); test_cond("abs2lenRelative 3", strcmp(domain, "@") == 0); } char *ss = readFile(argv[3]); char buf[1000]; int idx = 0; int err; char errstr[ERR_STR_LEN]; fprintf(stderr, "\n"); while ((err=readFullRecord(errstr, &ss, buf, 1000, &idx)) == OK_CODE) { fprintf(stderr, "l%d:%s \n", idx, buf); } fprintf(stderr, "\n"); zone *z; loadZoneFromFile(SOCKET_ID_HEAP, argv[3], &z); sds s = zoneToStr(z); printf("%s\n", s); sdsfree(s); // { // zone *z = zoneDictFetchVal(zd, "\7example\3com"); // sds s = zoneToStr(z); // LOG_DEBUG("%s", s); // sdsfree(s); // zoneDecRef(z); // } test_report(); return 0; }
static void Init(rtems_task_argument arg) { test_context *ctx = &test_instance; TEST_BEGIN(); test_delay_nanoseconds(ctx); test_delay_ticks(ctx); test_overheads(ctx); test_converter(); test_report(ctx); TEST_END(); rtems_test_exit(0); }
static test_result pic (char *res, char *raw) { int i; test_result result = TEST_OK; if (load_pic (res) == TEST_FAIL) return TEST_FAIL; test_report ("drawing and comparing 50x"); for (i = 0; i < 50; i++) { decode_picture (0,1); if ((result = compare_pic (raw)) != TEST_OK) break; } free (game.pictures[0].rdata); return result; }
int main(int argc, char **argv) { test_init(argc, argv); // start the server struct memcached_process_handle* mchandle = new_memcached(0, ""); if (!mchandle) { fprintf(stderr,"Could not start memcached process\n\n"); exit(0); } struct Memcache* memcache = libmemc_create(Automatic); if (libmemc_add_server(memcache, "127.0.0.1", mchandle->port) == -1) { fprintf(stderr,"Could not add server\n\n"); exit(0); } // wait for early second struct timeval tv; while (1) { gettimeofday(&tv, NULL); if (tv.tv_usec < 500000) break; usleep(100000); // 1/10th of a second sleeps until time changes. } struct Item item = {0}; // We choose expiry time = 2 secs instead of 1 sec. // 1 sec is too small for these tests since memcached updates current_time once a second // which means that an item will frequently expire in much less than a second if exptime=1 setItem(&item, 0, "foo", 3, 0, "fooval", 6, 2); ok_test(!libmemc_set(memcache, &item), "stored foo", "failed to store foo"); mem_get_is(memcache, &item, "foo == 'fooval'", "foo != 'fooval'"); usleep(2500000); // sleep 2.5 secs struct Item item2 = {0}; setItem(&item2, 0, "foo", 3, 0, NULL, 0, 0); mem_get_is(memcache, &item2, "foo == <undef>", "foo != <undef>"); gettimeofday(&tv, NULL); item.exptime = tv.tv_sec - 1; ok_test(!libmemc_set(memcache, &item), "stored foo", "failed to store foo"); mem_get_is(memcache, &item2, "already expired", "not expired"); struct Item item3 = {0}; setItem(&item3, 0, "foo", 3, 0, "foov+1", 6, 2); ok_test(!libmemc_set(memcache, &item3), "stored foo", "failed to store foo"); mem_get_is(memcache, &item3, "foo == 'foov+1'", "foo != 'foov+1'"); usleep(2500000); // sleep 2.5 secs struct Item item4 = {0}; setItem(&item4, 0, "foo", 3, 0, NULL, 0, 0); mem_get_is(memcache, &item4, "now expired", "not expired"); gettimeofday(&tv, NULL); struct Item item5 = {0}; setItem(&item5, 0, "boo", 3, 0, "booval", 6, tv.tv_sec - 20); ok_test(!libmemc_set(memcache, &item3), "stored boo", "failed to store boo"); struct Item item6 = {0}; setItem(&item6, 0, "boo", 3, 0, NULL, 0, 0); mem_get_is(memcache, &item6, "now expired", "not expired"); libmemc_destroy(memcache); test_report(); }
int main(int argc, char **argv) { test_init(argc, argv); struct memcached_process_handle* mchandle = new_memcached(0, ""); // start the server if (!mchandle) { fprintf(stderr,"Could not start memcached process\n\n"); exit(0); } struct Memcache* memcache = libmemc_create(Automatic); if (libmemc_add_server(memcache, "127.0.0.1", mchandle->port) == -1) { fprintf(stderr,"Could not add server\n\n"); exit(0); } int usock = new_udp_sock(mchandle); char ok_str[50]; char notok_str[50]; if (libmemc_get_protocol(memcache) == Textual) { // set foo struct Item item = {0}; setItem(&item, 0, "foo", 3, 0, "fooval", 6, 0); ok_test(!libmemc_set(memcache, &item), "stored foo", "failed to store foo"); mem_get_is(memcache, &item, "foo == fooval", "foo != fooval"); test_single(usock); int offset[3] = {1, 1, 2}; for (int i=0; i<3; i++) { udp_data *res = send_udp_request(usock, 160 + offset[i], "get foo\r\n"); ok_test(res != NULL, "got result", "did not get result"); ok_test(res[0].packets == 1, "one packet", "not one packet"); ok_test(res[0].seq_num == 0, "only got seq number 0", "did not only get seq number 0"); ok_test(!memcmp(res[0].body, "VALUE foo 0 6\r\nfooval\r\nEND\r\n", 28), "payload is as expected", "payload is not as expected"); sprintf(ok_str, "request id in response %d is correct", res[0].request_id); sprintf(notok_str, "request id in response %d is not correct", res[0].request_id); ok_test(res[0].request_id == 160 + offset[i], ok_str, notok_str); if (res) free(res); } // testing non-existent stuff udp_data *res = send_udp_request(usock, 404, "get notexist\r\n"); ok_test(res != NULL, "got result", "did not get result"); ok_test(res[0].packets == 1, "one packet", "not one packet"); ok_test(res[0].seq_num == 0, "only got seq number 0", "did not only get seq number 0"); sprintf(ok_str, "request id %d correct", res[0].request_id); sprintf(notok_str, "request id %d not correct", res[0].request_id); ok_test(res[0].request_id == 404, ok_str, notok_str); ok_test(!memcmp(res[0].body, "END\r\n", 5), "payload is as expected", "payload is not as expected"); if (res) free(res); int size = 4096; // 256 kB char *big = malloc(size); for (int i=0; i<(size/4); i++) { memcpy(big + i*4, "abcd", 4); } setItem(&item, 0, "big", 3, 0, big, size, 0); ok_test(!libmemc_set(memcache, &item), "stored big", "failed to store big"); mem_get_is(memcache, &item, "big value matches", "big value does not match"); res = send_udp_request(usock, 999, "get big\r\n"); ok_test(res[0].packets == 3, "three packet response", "not three packet response"); ok_test(!memcmp(res[0].body, "VALUE big 0 4096\r\n", 18), "first packet has value line", "first packet is missing value line"); ok_test(strstr(res[2].body, "END\r\n") != NULL, "last packet has end", "last packet is missing end"); ok_test(res[1].request_id == 999, "request id of middle packet is correct", "request id of middle packet is incorrect"); if (res) free(res); } else { fprintf(stdout, "Tests not implemented for binary protocol\n"); } libmemc_destroy(memcache); test_report(); }
void AlarmCallback(OSAlarm *alarm, OSContext *context) { test_assert(alarm == &sAlarm); test_report("AlarmCallback called."); }
int main(int argc, char **argv) { printf("Arguments: %i\n",argc); int arg; for (arg = 0 ; arg < argc ; arg++) printf(" %i: %s;\n", arg,argv[arg]); if ((argc > 1) && argv[1][0] == '1') { test = 1; printf("Set test\n"); } libusb_device **list; //libusb_device *accel; libusb_context *ctx = NULL; libusb_init(&ctx); libusb_set_debug(ctx,3); names_init("./usb.ids"); ssize_t cnt = libusb_get_device_list(ctx,&list); ssize_t i = 0; int err = 0; if (cnt < 0) { printf("Error getting usb device list\n"); exit(1); } for (i = 0 ; i < cnt ; i++) { libusb_device *device = list[i]; struct libusb_device_descriptor desc; err = libusb_get_device_descriptor(device,&desc); if (err < 0) printf("Error getting device descriptor: %i\n",err); else { if (desc.idVendor == VENDOR_ID && desc.idProduct == PRODUCT_ID) { printf("Device Found: idVendor = %xh, idProduct = %xh\n",desc.idVendor, desc.idProduct); printdev(device); int reattach = 0; libusb_device_handle *handle; int r = libusb_open(device,&handle); if (r < 0){ printf("Error opening device: %i\n",r); exit(1); } if (libusb_kernel_driver_active(handle,0)) { printf("Device already has a kernel driver\n"); r = libusb_detach_kernel_driver(handle,0); if (r < 0) { printf("Unable to detach kernel driver: %i\n",r); goto CLOSE; } reattach = 1; } if (libusb_claim_interface(handle,0) == 0) { printf("Claimed Device\n"); dump_hid(device,handle); if (test) { printf("Beginning report testing\n"); test_report(handle); } } CLOSE: libusb_release_interface(handle, 0); if (reattach) { r = libusb_attach_kernel_driver(handle,0); if (r < 0) { printf("Failed to reattach kernel driver: %i\n",r); switch (-1) { case LIBUSB_ERROR_IO: printf("I/O error\n"); break; case LIBUSB_ERROR_ACCESS: printf("Access Denied\n"); break; case LIBUSB_ERROR_NOT_FOUND: printf("Kernel driver wasn't active\n"); break; case LIBUSB_ERROR_INVALID_PARAM: printf("Interface doesn't exist\n"); break; case LIBUSB_ERROR_NO_DEVICE: printf("Device was disconnected\n"); break; case LIBUSB_ERROR_BUSY: printf("Interface is still claimed\n"); break; case LIBUSB_ERROR_TIMEOUT: printf("Operation timed out\n"); break; case LIBUSB_ERROR_OVERFLOW: printf("Overflow\n"); break; case LIBUSB_ERROR_PIPE: printf("Pipe Error\n"); break; case LIBUSB_ERROR_INTERRUPTED: printf("System call interrupted\n"); break; case LIBUSB_ERROR_NO_MEM: printf("Insufficient Memory\n"); break; case LIBUSB_ERROR_NOT_SUPPORTED: printf("Operation not supported\n"); break; default: printf("Some other error occured\n"); break; } } } libusb_close(handle); } } } libusb_free_device_list(list,1); libusb_exit(ctx); exit(err); }
int main(int argc, char **argv) { test_init(argc, argv); // start the server struct memcached_process_handle* mchandle = new_memcached(0, ""); if (!mchandle) { fprintf(stderr,"Could not start memcached process\n\n"); exit(0); } struct Memcache* memcache = libmemc_create(Automatic); if (libmemc_add_server(memcache, "127.0.0.1", mchandle->port) == -1) { fprintf(stderr,"Could not add server\n\n"); exit(0); } struct Item item = {0}; setItem(&item, 0, "num", 3, 0, "1", 1, 0); ok_test(!libmemc_set(memcache, &item), "stored num", "failed to store num"); mem_get_is(memcache, &item, "num == '1'", "num != '1'"); ok_test(!libmemc_incr(memcache, &item, 1) && !memcmp(item.data, "2", item.size), "+ 1 = 2", "+ 1 != 2"); mem_get_is(memcache, &item, "num == '2'", "num != '2'"); ok_test(!libmemc_incr(memcache, &item, 8) && !memcmp(item.data, "10", item.size), "+ 8 = 10", "+ 8 != 10"); mem_get_is(memcache, &item, "num == '10'", "num != '10'"); ok_test(!libmemc_decr(memcache, &item, 1) && !memcmp(item.data, "9", item.size), "- 1 = 9", "- 1 != 9"); ok_test(!libmemc_decr(memcache, &item, 9) && !memcmp(item.data, "0", item.size), "- 9 = 0", "- 9 != 0"); ok_test(!libmemc_decr(memcache, &item, 5) && !memcmp(item.data, "0", item.size), "- 5 = 0", "- 5 != 0"); setItem(&item, 0, "num", 3, 0, "4294967296", 10, 0); ok_test(!libmemc_set(memcache, &item), "stored 2**32", "failed to store 2**32"); ok_test(!libmemc_incr(memcache, &item, 1) && !memcmp(item.data, "4294967297", item.size), "4294967296 + 1 = 4294967297", "4294967296 + 1 != 4294967297"); setItem(&item, 0, "num", 3, 0, "18446744073709551615", 20, 0); ok_test(!libmemc_set(memcache, &item), "stored 2**64-1", "failed to store 2**64-1"); ok_test(!libmemc_incr(memcache, &item, 1) && !memcmp(item.data, "0", item.size), "(2**64 - 1) + 1 = 0", "(2**64 - 1) + 1 != 0"); if (libmemc_get_protocol(memcache) == Textual) { setItem(&item, 0, "bogus1", 6, 0, "0", 1, 0); ok_test((libmemc_decr(memcache, &item, 5) == -1), "can't decr bogus key", "can decr bogus key"); setItem(&item, 0, "bogus2", 6, 0, "0", 1, 0); ok_test((libmemc_incr(memcache, &item, 5) == -1), "can't incr bogus key", "can incr bogus key"); } else { setItem(&item, 0, "bogus1", 6, 0, "4", 1, 0xffffffff); ok_test((libmemc_decr(memcache, &item, 5) == -1), "can't decr bogus key when expiry == 0xffffffff", "can decr bogus key when expiry == 0xffffffff"); setItem(&item, 0, "bogus2", 6, 0, "4", 1, 0xffffffff); ok_test((libmemc_incr(memcache, &item, 5) == -1), "can't incr bogus key when expiry == 0xffffffff", "can incr bogus key when expiry == 0xffffffff"); setItem(&item, 0, "bogus1", 6, 0, "4", 1, 0); ok_test(!libmemc_decr(memcache, &item, 5), "can decr bogus key when expiry != 0xffffffff", "can't decr bogus key when expiry != 0xffffffff"); setItem(&item, 0, "bogus2", 6, 0, "4", 1, 0); ok_test(!libmemc_incr(memcache, &item, 5), "can incr bogus key when expiry != 0xffffffff", "can't incr bogus key when expiry != 0xffffffff"); } setItem(&item, 0, "text", 4, 0, "hi", 2, 0); ok_test(!libmemc_set(memcache, &item), "stored text", "failed to store text"); ok_test(!libmemc_incr(memcache, &item, 1) && !memcmp(item.data, "1", item.size), "hi + 1 = 1", "hi + 1 != 1"); setItem(&item, 0, "text", 4, 0, "hi", 2, 0); ok_test(!libmemc_set(memcache, &item), "stored text", "failed to store text"); ok_test(!libmemc_decr(memcache, &item, 1) && !memcmp(item.data, "0", item.size), "hi - 1 = 0", "hi - 1 != 0"); libmemc_destroy(memcache); test_report(); }
static ErrorNumber test_valueId( TA_PMValueIdTest *test ) { unsigned int i; TA_TradeLog *tradeLog; TA_PM *pm; ErrorNumber errorNumber; TA_RetCode retCode; TA_Real theValue; const char *tempStr; /* Allocate and build the TA_TradeLog */ retCode = TA_TradeLogAlloc( &tradeLog ); if( retCode != TA_SUCCESS ) return TA_PM_TEST_VALUE_ID_FAILED_0; /* Add all the transaction. For simplicity, make these * all the same instrument. */ #define TA_SAFETY_NET_LIMIT 100 i = 0; while( (((void *)test->inputs[i].type) != ((void *)-1)) && (i<TA_SAFETY_NET_LIMIT) ) { retCode = TA_TradeLogAdd( tradeLog, &test->inputs[i] ); if( retCode != TA_SUCCESS ) { printRetCode( retCode ); TA_TradeLogFree( tradeLog ); return TA_PM_TEST_VALUE_ID_FAILED_1; } i++; } if( i >= TA_SAFETY_NET_LIMIT ) { printf( "Failed: Number of transaction exceed %d limit\n", TA_SAFETY_NET_LIMIT ); return TA_PM_TEST_VALUE_ID_FAILED_2; } #undef TA_SAFETY_NET_LIMIT /* Build the TA_PM */ retCode = TA_PMAlloc( &test->startDate, &test->endDate, test->initialCapital, &pm ); if( retCode != TA_SUCCESS ) { printRetCode( retCode ); TA_TradeLogFree( tradeLog ); return TA_PM_TEST_VALUE_ID_FAILED_3; } /* Add the trade log to that PM */ retCode = TA_PMAddTradeLog( pm, tradeLog ); if( retCode != TA_SUCCESS ) { printRetCode( retCode ); return TA_PM_TEST_VALUE_ID_FAILED_4; } /* Test the report feature. Again just to detect * software hanging/bad pointer. */ errorNumber = test_report( pm, 0 ); if( errorNumber != TA_TEST_PASS ) return errorNumber; /* Check the requested TA_PMArrayId */ #define TA_SAFETY_NET_LIMIT 30 i=0; while( (((int)test->toCheck[i].id) != -1) && (i<TA_SAFETY_NET_LIMIT) ) { switch( test->toCheck[i].grp ) { case TA_PM_ALL_TRADES: tempStr = "TA_PM_ALL_TRADES"; break; case TA_PM_SHORT_TRADES: tempStr = "TA_PM_SHORT_TRADES"; break; case TA_PM_LONG_TRADES: tempStr = "TA_PM_LONG_TRADES"; break; default: tempStr = "Invalid Group Id"; } retCode = TA_PMValue( pm, test->toCheck[i].id, test->toCheck[i].grp, &theValue ); if( retCode != test->toCheck[i].expectedRetCode ) { printRetCode( test->toCheck[i].expectedRetCode ); printRetCode( retCode ); printf( "Failed: TA_PMValue expectedRetCode != retCode (%d != %d)\n", test->toCheck[i].expectedRetCode, retCode ); printf( "Failed: For %d:%s %d:%s\n", test->toCheck[i].id, TA_PMValueIdString(test->toCheck[i].id), test->toCheck[i].grp, tempStr ); return TA_PM_TEST_VALUE_ID_FAILED_5; } if( !TA_REAL_EQ(theValue,test->toCheck[i].expectedValue,0.01) ) { printf( "Failed: TA_PMValue expectedValue != theValue (%f != %f)\n", test->toCheck[i].expectedValue, theValue ); printf( "Failed: For %d:%s %d:%s\n", test->toCheck[i].id, TA_PMValueIdString(test->toCheck[i].id), test->toCheck[i].grp, tempStr ); return TA_PM_TEST_VALUE_ID_FAILED_6; } i++; } if( i >= TA_SAFETY_NET_LIMIT ) { printf( "Failed: Number of checks exceed %d limit\n", TA_SAFETY_NET_LIMIT ); return TA_PM_TEST_VALUE_ID_FAILED_7; } #undef TA_SAFETY_NET_LIMIT /* Check for any potential software hanging/bad pointer. */ errorNumber = checkNoHang( pm ); if( errorNumber != TA_TEST_PASS ) return errorNumber; /* Free up everything */ retCode = TA_TradeLogFree( tradeLog ); if( retCode != TA_SUCCESS ) { printRetCode( retCode ); return TA_PM_TEST_VALUE_ID_FAILED_8; } retCode = TA_PMFree( pm ); if( retCode != TA_SUCCESS ) { printRetCode( retCode ); return TA_PM_TEST_VALUE_ID_FAILED_9; } return TA_TEST_PASS; }
test_report benchmark_test_with_internal_configuration(std::string test_casename, const std::string function_name, int flag, int nVar){ std::ofstream report_file("tests_report_file.txt", std::ios::app); time_t start_time; time (&start_time); std::cout << "test case: " << test_casename << " starts with internal configuration" << std::endl; general_configuration internal_configuration_old("no_filename", 10, //1 - diversify 5, //2 - intensify 15, //3 - reduce 0.00, //4 - SS 0.5, //5 - SSRF 1, //6 - save step 3, //7 - sampling nVar, //8 - nVar 2, //9 - nObj 0, //10 loop limit 3000, //11 evaluations limit 0, //12 Improvements limit , number of consecutive improvements 4, //13 - number of regions 6, //14 - STM size "HV", // 15 "full", //16 -0.05, //17 - starting point 200, //18 300); //19 general_configuration internal_configuration("configuration.txt"); ObjFunction2 test_reference_point=ObjFunction2(2, 22.0); ObjFunction2 test_penalty_point=ObjFunction2(2,33333.0); Point2 test_lower_bound=Point2(nVar,0.0); test_lower_bound[0]=5.0; test_lower_bound[1]=1.0; test_lower_bound[2]=11.0; Point2 test_upper_bound=Point2(nVar,1.0); test_upper_bound[0]=11.0; test_upper_bound[1]=200.0; test_upper_bound[2]=29.0; Point2 test_starting_point=Point2(nVar,0.5); test_starting_point[0]=7.0; test_starting_point[1]=100.0; test_starting_point[2]=24.5; Point2 test_current_step=Point2(nVar,0.05); test_current_step[0]=0.1666666; test_current_step[1]=0.050251256; test_current_step[2]=0.055555556; Overall_Optimisation_Configuration_Settings myConf2(test_casename, internal_configuration, test_reference_point, test_penalty_point, test_lower_bound, test_upper_bound, test_starting_point, test_current_step); const unsigned int n_of_variables=myConf2.getExternalConfigurationFile().getVar(); const unsigned int n_of_objectives=myConf2.getExternalConfigurationFile().getObj(); objective_function_formulae obj_function(n_of_objectives); ObjectiveFunctionBasic<double> TS_ObjFunc(myConf2, obj_function); Container2 MTM(n_of_variables, n_of_objectives, "MTM","./memories"); Container2 IM(n_of_variables, n_of_objectives, "IM","./memories"); Container2 HISTORY(n_of_variables, n_of_objectives, "HISTORY","./memories"); STM_Container2 STM(myConf2.getExternalConfigurationFile().getStmSize(), n_of_variables, "STM", "./memories"); LTM_Container2Basic2<double> LTM( n_of_variables , myConf2.getExternalConfigurationFile().getRegions(), myConf2.get_lower_bound(), myConf2.get_upper_bound(),"LTM", "./memories"); std::cout << "Memories done!" << std::endl; TabuSearch TS(myConf2, flag, TS_ObjFunc, MTM, IM, HISTORY, STM, LTM); double hyper_volume_indicator=TS.search2(); time_t end; time (&end); double dif = difftime (end,start_time); std::cout << "end in " << dif<< "seconds" << std::endl; report_file << test_casename << "\t" << n_of_variables << "\t" << dif << " seconds " << __DATE__ << "\t" << __TIME__ << std::endl; report_file.close(); return test_report(myConf2.getCaseName(), TS.getDatumPnt(), hyper_volume_indicator) ; }
static ErrorNumber test_onetransaction_only( TA_KEY_TYPE keyTypeTest ) { TA_RetCode retCode; TA_Instrument instrument; TA_Transaction transaction; TA_TradeLog *tradeLog; ErrorNumber errorNumber; TA_PM *allocatedPM; /* Allocate an empty TA_TradeLog. */ retCode = TA_TradeLogAlloc( &tradeLog ); if( (retCode != TA_SUCCESS) || (tradeLog == NULL) ) { printRetCode( retCode ); printf( "Failed: TA_TradeLogAlloc bad retCode! [%d]\n", retCode ); return TA_PM_EMPTY_TA_TRADE_LOG_TESTS_0; } /* Add one TA_Transaction */ switch( keyTypeTest ) { case TA_KEY_TYPE_INTEGER: TA_InstrumentInitWithUserKey( &instrument, 0x12345432 ); break; case TA_KEY_TYPE_CAT: TA_InstrumentInit( &instrument, "CATONLY", NULL ); break; case TA_KEY_TYPE_SYM: TA_InstrumentInit( &instrument, NULL, "S" ); break; case TA_KEY_TYPE_CATSYM: TA_InstrumentInit( &instrument, "CATABCDEFGHIJKLMNOPQRSTUVWXYZ", "SYM012345678901234567890" ); break; default: return TA_PM_ERR_INVALID_KEY_TYPE; } transaction.id = &instrument; transaction.price = 34.45; transaction.quantity = 8765; TA_TimestampCopy( &transaction.timestamp, ×tampNow ); transaction.type = TA_LONG_ENTRY; retCode = TA_TradeLogAdd( tradeLog, &transaction ); if( retCode != TA_SUCCESS ) { printRetCode( retCode ); printf( "Failed: TA_TradeLogAdd bad retCode %d\n", retCode ); return TA_PM_TRADELOGADD_ONE_TRADE_FAILED; } /* Create a TA_PM */ retCode = TA_PMAlloc( ×tampNow, ×tampNow, 1000, &allocatedPM ); if( retCode != TA_SUCCESS ) { TA_TradeLogFree( tradeLog ); printRetCode( retCode ); printf( "Failed: TA_PMAlloc bad retCode %d\n", retCode ); return TA_PM_TRADELOGADD_ONE_TRADE_FAILED_1; } retCode = TA_PMAddTradeLog( allocatedPM, tradeLog ); if( retCode != TA_SUCCESS ) { TA_PMFree( allocatedPM ); TA_TradeLogFree( tradeLog ); printRetCode( retCode ); printf( "Failed: TA_PMAddTradeLog bad retCode %d\n", retCode ); return TA_PM_TRADELOGADD_ONE_TRADE_FAILED_2; } /* Verify the NB of TRADE */ errorNumber = checkPMvalues( allocatedPM, 0, 0, 0, 0 ); if( errorNumber != TA_TEST_PASS ) return errorNumber; errorNumber = checkNoHang( allocatedPM ); if( errorNumber != TA_TEST_PASS ) return errorNumber; /* Building a report should work */ errorNumber = test_report( allocatedPM, 0 ); if( errorNumber != TA_TEST_PASS ) return errorNumber; /* Clean-up and exit */ retCode = TA_PMFree( allocatedPM ); if( retCode != TA_SUCCESS ) { TA_PMFree( allocatedPM ); TA_TradeLogFree( tradeLog ); printRetCode( retCode ); printf( "Failed: TA_PMFree bad retCode %d\n", retCode ); return TA_PM_TRADELOGADD_ONE_TRADE_FAILED_3; } retCode = TA_TradeLogFree( tradeLog ); if( retCode != TA_SUCCESS ) { printRetCode( retCode ); printf( "Failed: TA_TradeLogFree bad retCode %d\n", retCode ); return TA_PM_TRADELOGFREE_ONE_TRADE_FAILED; } return TA_TEST_PASS; }
static ErrorNumber test_onetrade_only( TA_KEY_TYPE keyTypeTest, TA_TransactionType transactionType, unsigned int winningTrade ) { TA_RetCode retCode; TA_Instrument instrument; TA_Transaction transaction; TA_TradeLog *tradeLog; TA_PM *allocatedPM; ErrorNumber errorNumber; /* Allocate a TA_TradeLog. */ retCode = TA_TradeLogAlloc( &tradeLog ); if( (retCode != TA_SUCCESS) || (tradeLog == NULL) ) { printRetCode( retCode ); printf( "Failed: TA_TradeLogAlloc bad retCode! [%d]\n", retCode ); return TA_PM_EMPTY_TA_TRADE_LOG_TESTS_0; } /* Add the entry TA_Transaction */ switch( keyTypeTest ) { case TA_KEY_TYPE_INTEGER: TA_InstrumentInitWithUserKey( &instrument, 0 ); break; case TA_KEY_TYPE_CAT: TA_InstrumentInit( &instrument, "CATONLY", "" ); break; case TA_KEY_TYPE_SYM: TA_InstrumentInit( &instrument, "", "SYMONLY" ); break; case TA_KEY_TYPE_CATSYM: TA_InstrumentInit( &instrument, "C", "S" ); break; default: return TA_PM_ERR_INVALID_KEY_TYPE; } transaction.id = &instrument; transaction.price = 10.00; transaction.quantity = 1234; TA_TimestampCopy( &transaction.timestamp, ×tampNowPlusOneYear ); transaction.type = transactionType; retCode = TA_TradeLogAdd( tradeLog, &transaction ); if( retCode != TA_SUCCESS ) { printf( "Failed: TA_TradeLogAdd bad retCode %d\n", retCode ); return TA_PM_2TRADETST_TRADELOGADD_1; } /* Set the corresponsing exit transaction type. * Also make the exit price either winning * or loosing. */ if( transactionType == TA_LONG_ENTRY ) { transaction.type = TA_LONG_EXIT; if( winningTrade ) transaction.price = 12.00; else transaction.price = 9.50; } else if( transactionType == TA_SHORT_ENTRY ) { transaction.type = TA_SHORT_EXIT; if( winningTrade ) transaction.price = 9.25; else transaction.price = 11.00; } else return TA_PM_2TRADETST_BAD_TRADE_TYPE; /* Add the exit transaction. */ retCode = TA_TradeLogAdd( tradeLog, &transaction ); if( retCode != TA_SUCCESS ) { TA_TradeLogFree( tradeLog ); printRetCode( retCode ); printf( "Failed: TA_TradeLogAdd bad retCode %d\n", retCode ); return TA_PM_2TRADETST_TRADELOGADD_2; } /* Create a TA_PM */ retCode = TA_PMAlloc( ×tampNow, ×tampNowPlusOneYear, 1000, &allocatedPM ); if( retCode != TA_SUCCESS ) { TA_TradeLogFree( tradeLog ); printRetCode( retCode ); printf( "Failed: TA_PMAlloc bad retCode %d\n", retCode ); return TA_PM_2TRADETST_PMALLOC_FAILED; } retCode = TA_PMAddTradeLog( allocatedPM, tradeLog ); if( retCode != TA_SUCCESS ) { TA_PMFree( allocatedPM ); TA_TradeLogFree( tradeLog ); printRetCode( retCode ); printf( "Failed: TA_PMAddTradeLog bad retCode %d\n", retCode ); return TA_PM_2TRADETST_PMADDTRADELOG_FAILED; } /* Verify the NB of TRADE and the net profit */ if( transactionType == TA_LONG_ENTRY ) { if( winningTrade ) errorNumber = checkPMvalues( allocatedPM, 1, 0, 2468, 0 ); else errorNumber = checkPMvalues( allocatedPM, 1, 0, -617, 0 ); } else if( transactionType == TA_SHORT_ENTRY ) { if( winningTrade ) errorNumber = checkPMvalues( allocatedPM, 0, 1, 0, 925.5 ); else errorNumber = checkPMvalues( allocatedPM, 0, 1, 0, -1234); } else errorNumber = TA_PM_UNKNOWN_TRANSACTION_TYPE; if( errorNumber != TA_TEST_PASS ) return errorNumber; errorNumber = checkNoHang( allocatedPM ); if( errorNumber != TA_TEST_PASS ) return errorNumber; /* Building a report should work */ errorNumber = test_report( allocatedPM, 0 ); if( errorNumber != TA_TEST_PASS ) return errorNumber; /* Clean-up and exit */ retCode = TA_PMFree( allocatedPM ); if( retCode != TA_SUCCESS ) { TA_PMFree( allocatedPM ); TA_TradeLogFree( tradeLog ); printRetCode( retCode ); printf( "Failed: TA_PMFree bad retCode %d\n", retCode ); return TA_PM_2TRADETST_PMFREE_FAILED; } retCode = TA_TradeLogFree( tradeLog ); if( retCode != TA_SUCCESS ) { printRetCode( retCode ); printf( "Failed: TA_TradeLogFree bad retCode %d\n", retCode ); return TA_PM_TRADELOGFREE_ONE_TRADE_FAILED; } return TA_TEST_PASS; }
int main(int argc, char **argv) { MEMHeapHandle mem2 = MEMGetBaseHeapHandle(MEM_BASE_HEAP_MEM2); test_assert(mem2); test_report("Allocating %d bytes from default heap", HeapSize); void *heapAddr = MEMAllocFromExpHeapEx(mem2, HeapSize, 4); test_assert(heapAddr); // Unalign the frame heap base address void *frameHeapAddr = heapAddr + 1; test_report("Creating frame heap at %p", frameHeapAddr); MEMHeapHandle frameHeap = MEMCreateFrmHeapEx(frameHeapAddr, HeapSize, 0); test_report("Frame heap created at %p", frameHeap); test_assert(frameHeap); test_assert((((uint32_t)frameHeap) % 4) == 0); uint32_t freeSize1 = MEMGetAllocatableSizeForFrmHeapEx(frameHeap, 4); test_report("Free Size before allocation: %d", freeSize1); test_assert((freeSize1 % 4) == 0); { // Allocate an unaligned block from head with an unaligned size void *unalignedBlock = MEMAllocFromFrmHeapEx(frameHeap, 5, 1); uint32_t unalignedBlockAddress = (uint32_t)unalignedBlock; test_report("Unaligned head block allocated at %p", unalignedBlock); test_assert(unalignedBlock); // Allocate an aligned block from head and ensure it is aligned void *alignedBlock = MEMAllocFromFrmHeapEx(frameHeap, 1024, 512); uint32_t alignedBlockAddress = (uint32_t)alignedBlock; test_report("Aligned head block allocated at %p", alignedBlock); test_assert(alignedBlock); test_assert((((uint32_t)alignedBlock) % 512) == 0); test_assert(alignedBlockAddress - unalignedBlockAddress >= 5); } { // Allocate an unaligned block from tail with an unaligned size void *unalignedBlock = MEMAllocFromFrmHeapEx(frameHeap, 5, -1); uint32_t unalignedBlockAddress = (uint32_t)unalignedBlock; test_report("Unaligned tail block allocated at %p", unalignedBlock); test_assert(unalignedBlock); // Allocate an aligned block from tail and ensure it is aligned void *alignedBlock = MEMAllocFromFrmHeapEx(frameHeap, 1024, -512); uint32_t alignedBlockAddress = (uint32_t)alignedBlock; test_report("Aligned tail block allocated at %p", alignedBlock); test_assert(alignedBlock); test_assert((((uint32_t)alignedBlock) % 512) == 0); test_assert(unalignedBlockAddress - alignedBlockAddress >= 512); } // Free all memory MEMFreeToFrmHeap(frameHeap, MEM_FRM_HEAP_FREE_ALL); uint32_t freeSize3 = MEMGetAllocatableSizeForFrmHeapEx(frameHeap, 4); test_report("Free Size after free: %d", freeSize3); test_assert(freeSize1 == freeSize3); MEMDestroyFrmHeap(frameHeap); MEMFreeToExpHeap(mem2, heapAddr); return 0; }
// Main Function void main(void) { // Step 1: Setup the system clock /* Disable the watchdog timer, initialize the system clock, * PLL and configure the peripheral clock. */ InitSysCtrl(); // Step 2: Initialize PIE control /* Initialize PIE control, disable all interrupts and * then copy over the PIE Vector table from BootROM to RAM */ DINT; InitPieCtrl(); IER = 0x00000000; IFR = 0x00000000; InitPieVectTable(); /* Assign user defined ISR to the PIE vector table */ EALLOW; PieVectTable.CLA1_INT1 = &cla1_task1_isr; PieVectTable.CLA1_INT2 = &cla1_task2_isr; PieVectTable.CLA1_INT3 = &cla1_task3_isr; PieVectTable.CLA1_INT4 = &cla1_task4_isr; PieVectTable.CLA1_INT5 = &cla1_task5_isr; PieVectTable.CLA1_INT6 = &cla1_task6_isr; PieVectTable.CLA1_INT7 = &cla1_task7_isr; PieVectTable.CLA1_INT8 = &cla1_task8_isr; EDIS; //Copy over the CLA code and Tables memcpy(&Cla1funcsRunStart, &Cla1funcsLoadStart, (Uint32)&Cla1funcsLoadSize); memcpy(&Cla1mathTablesRunStart, &Cla1mathTablesLoadStart, (Uint32)&Cla1mathTablesLoadSize); /* Compute all CLA task vectors */ EALLOW; Cla1Regs.MVECT1 = (Uint16)((Uint32)&Cla1Task1 - (Uint32)&Cla1Prog_Start); Cla1Regs.MVECT2 = (Uint16)((Uint32)&Cla1Task2 - (Uint32)&Cla1Prog_Start); Cla1Regs.MVECT3 = (Uint16)((Uint32)&Cla1Task3 - (Uint32)&Cla1Prog_Start); Cla1Regs.MVECT4 = (Uint16)((Uint32)&Cla1Task4 - (Uint32)&Cla1Prog_Start); Cla1Regs.MVECT5 = (Uint16)((Uint32)&Cla1Task5 - (Uint32)&Cla1Prog_Start); Cla1Regs.MVECT6 = (Uint16)((Uint32)&Cla1Task6 - (Uint32)&Cla1Prog_Start); Cla1Regs.MVECT7 = (Uint16)((Uint32)&Cla1Task7 - (Uint32)&Cla1Prog_Start); Cla1Regs.MVECT8 = (Uint16)((Uint32)&Cla1Task8 - (Uint32)&Cla1Prog_Start); EDIS; // Step 3 : Mapping CLA tasks /* All tasks are enabled and will be started by an ePWM trigger * Map CLA program memory to the CLA and enable software breakpoints */ EALLOW; Cla1Regs.MPISRCSEL1.bit.PERINT1SEL = CLA_INT1_NONE; Cla1Regs.MPISRCSEL1.bit.PERINT2SEL = CLA_INT2_NONE; Cla1Regs.MPISRCSEL1.bit.PERINT3SEL = CLA_INT3_NONE; Cla1Regs.MPISRCSEL1.bit.PERINT4SEL = CLA_INT4_NONE; Cla1Regs.MPISRCSEL1.bit.PERINT5SEL = CLA_INT5_NONE; Cla1Regs.MPISRCSEL1.bit.PERINT6SEL = CLA_INT6_NONE; Cla1Regs.MPISRCSEL1.bit.PERINT7SEL = CLA_INT7_NONE; Cla1Regs.MPISRCSEL1.bit.PERINT8SEL = CLA_INT8_NONE; Cla1Regs.MIER.all = 0x00FF; EDIS; /* Enable CLA interrupts at the group and subgroup levels */ PieCtrlRegs.PIEIER11.all = 0xFFFF; IER = (M_INT11 ); EINT; // Enable Global interrupt INTM ERTM; // Enable Global realtime interrupt DBGM /* Switch the CLA program space to the CLA and enable software forcing * Also switch over CLA data ram 0 and 1 */ EALLOW; Cla1Regs.MMEMCFG.bit.PROGE = 1; Cla1Regs.MCTL.bit.IACKE = 1; Cla1Regs.MMEMCFG.bit.RAM0E = CLARAM0_ENABLE; Cla1Regs.MMEMCFG.bit.RAM1E = CLARAM1_ENABLE; EDIS; // Invoke Task(s) test_run(); // Report Results test_report(); #if HARDWARE {__asm(" ESTOP0");} #endif }