int main(int argc, const char* argv[] ) { int i,s,ret; int* res; pthread_t* threads=(pthread_t*)malloc(sizeof(pthread_t)*NUM_CLIENT_THREADS); int* ids=(int*) malloc(sizeof(int)*NUM_CLIENT_THREADS); ret=kos_init(NUM_CLIENT_THREADS,NUM_SERVER_THREADS,NUM_SHARDS); if (ret!=0) { printf("kos_init failed with code %d!\n",ret); return -1; } for (i=0; i<NUM_CLIENT_THREADS; i++) { ids[i]=i; if ( (s=pthread_create(&threads[i], NULL, &client_thread, &(ids[i])) ) ) { printf("pthread_create failed with code %d!\n",s); return -1; } } for (i=0; i<NUM_CLIENT_THREADS; i++) { s = pthread_join(threads[i], (void**) &res); if (s != 0) { printf("pthread_join failed with code %d",s); return -1; } } printf("\n--> TEST PASSED <--\n"); return 0; }
/* Note: last task registered will be the first to be scheduled. * running order can be important in current tasks design */ void mach_tasks_init() { kos_init(); #if defined(CONFIG_CALIBRATION) kos_new_task(task_calibration_entry, "CALIB", TASK_CALIB_STACK); #else planner_start_game(); #endif kos_new_task(task_controller_update, "CTRL", TASK_CTRL_STACK); kos_new_task(task_planner, "PLAN", TASK_PLAN_STACK); }
int main(int argc, const char* argv[] ) { char key[KEY_SIZE], value[KEY_SIZE], value2[KEY_SIZE]; char* v; int i,j; int client_id=0; kos_init(1,1,NUM_SHARDS); for (j=NUM_SHARDS-1; j>=0; j--) { for (i=NUM_EL; i>=0; i--) { sprintf(key, "k%d",i); sprintf(value, "val:%d",i); DEBUG("Element <%s,%s> being inserted in shard %d....\n", key, value, j); fflush(stdin); v=kos_put(client_id,j, key,value); if (v!=NULL) { printf("TEST FAILED - SHOULD RETURN NULL AND HAS RETURNED %s",v); exit(-1); } } } printf("------------------ ended inserting --------------------------------\n"); for (j=0; j<NUM_SHARDS; j++) { for (i=0; i<NUM_EL; i++) { sprintf(key, "k%d",i); sprintf(value, "val:%d",i); v=kos_get(client_id,j, key); if (v==NULL || strncmp(v,value,KEY_SIZE)!=0) { printf("TEST FAILED - Error on key %s, shard %d value should be %s and was returned %s",key,j,value,v); exit(-1); } } } printf("------------------- ended querying -------------------------------\n"); printf("\n--> TEST PASSED <--\n"); return 0; }
int main(int argc, const char* argv[] ) { int i,s,ret; int* res; long now, time(); char *ctime(); pthread_t* threads=(pthread_t*)malloc(sizeof(pthread_t)*NUM_CLIENT_THREADS); int* ids=(int*) malloc(sizeof(int)*NUM_CLIENT_THREADS); // this test uses NUM_CLIENT_THREADS shards, as, in some tests, each client executes commands in its own shard ret=kos_init(NUM_CLIENT_THREADS,NUM_SERVER_THREADS,NUM_CLIENT_THREADS); //printf("KoS inited"); if (ret!=0) { printf("kos_init failed with code %d!\n",ret); return -1; } for (i=0; i<NUM_CLIENT_THREADS; i++) { ids[i]=i; if ( (s=pthread_create(&threads[i], NULL, &client_thread, &(ids[i])) ) ) { printf("pthread_create failed with code %d!\n",s); return -1; } } time(&now); printf("BEGIN @ %s\n", ctime(&now)); for (i=0; i<NUM_CLIENT_THREADS; i++) { s = pthread_join(threads[i], (void**) &res); if (s != 0) { printf("pthread_join failed with code %d",s); return -1; } } time(&now); printf("END @ %s\n", ctime(&now)); printf("\n--> TEST PASSED <--\n"); return 0; }