void *logthread() { // Generate a default log file name before it is named. log1.csv, log2.csv, etc.. int logNum = 1; char lognumstr[4]; sprintf(lognumstr, "%d", logNum); strcpy(logString, "/home/cancorder/log"); //strcpy(logString, "log"); strcat(logString, lognumstr); strcat(logString, ".csv"); while(access(logString, F_OK ) != -1) { logNum ++; sprintf(lognumstr, "%d", logNum); strcpy(logString, "/home/cancorder/log"); //strcpy(logString, "log"); strcat(logString, lognumstr); strcat(logString, ".csv"); } // Open the file with write permissions f = fopen(logString, "w"); if(f == NULL) { printf("Error opening file!\n"); exit(1); } fprintf(f, "Runtime,System_Time,ErrorFrames,"); // Start inserting headers explore_tree(msg_tree, insert_headers_messages); explore_tree(signal_tree, insert_headers); // Generates headers once (can change to once in so many lines written) fprintf(f, "\n"); while(keepRunning) { usleep(25000); // Will cause "memory leak" since it can write to the file everything this quickly. Won't crash program data_log(signal_tree); // Datalog values in the signal tree fflush(f); } fclose(f); return NULL; }
char *explore_tests() { tree *first = NULL; struct _tree_data data[MAX_ELEMENT]; struct _tree_data tmp_elmnt; unsigned int result; unsigned int element_in_tree = 0; int i = 0; unsigned int r = 0; unsigned long rand_seed = (unsigned long) time(NULL); ILOG("Random seed: %lu", rand_seed); srand(rand_seed); for (i = 0; i < MAX_ELEMENT; i++) { data[i].key = rand(); data[i].value = 1; } // explore tree on a NULL tree explore_tree(first, count_treat, &r); if (r != 0) { ELOG("Wrong result on NULL tree"); return "Wrong result on NULL tree"; } // Try to allocate a new tree. first = init_dictionnary(data_cmp, data_print, data_delete, data_copy); if (first == NULL) { ELOG("Init dictionnary error"); return "Init dictionnary error"; } // explore tree on an empty tree explore_tree(first, count_treat, &r); if (r != 0) { ELOG("Wrong result on empty tree"); return "Wrong result on empty tree"; } // Add data verif_tree(first); for (i = 0; i < MAX_ELEMENT; i++) { tmp_elmnt.key = data[i].key; if (!is_present(first, &(tmp_elmnt))) { element_in_tree++; } result = insert_elmt(first, &(data[i]), sizeof(struct _tree_data)); if (result != element_in_tree) { ELOG("Wrong result of inserted element"); return "Wrong result of inserted element"; } verif_tree(first); } explore_tree(first, count_treat, &r); if (r != element_in_tree) { ELOG("Wrong result on empty tree: %d != %d", r, element_in_tree); return "Wrong result on empty tree"; } // Try to delete it delete_tree(first); return NULL; }