test_bug8_uart_commented_out.c
1 /******************************************************************************* 2 * test_bug8_uart_commented_out.c 3 * 4 * Bug #8 (FIXED): Debug helpers uart_print() and uart_println() are now 5 * uncommented and available as active code. 6 * 7 * Post-fix test: 8 * Read the source file and verify the functions are NOT inside comment blocks. 9 ******************************************************************************/ 10 #include <assert.h> 11 #include <stdio.h> 12 #include <string.h> 13 #include <stdlib.h> 14 15 /* Path to the source file (relative from test execution dir) */ 16 #define SOURCE_FILE "../9_1_3_C_Cpp_Code/main.cpp" 17 18 /* Helper: read entire file into malloc'd buffer. Returns NULL on failure. */ 19 static char *read_file(const char *path, long *out_size) 20 { 21 FILE *f = fopen(path, "r"); 22 if (!f) return NULL; 23 fseek(f, 0, SEEK_END); 24 long size = ftell(f); 25 fseek(f, 0, SEEK_SET); 26 char *buf = (char *)malloc(size + 1); 27 if (!buf) { fclose(f); return NULL; } 28 long nread = (long)fread(buf, 1, size, f); 29 buf[nread] = '\0'; 30 fclose(f); 31 if (out_size) *out_size = nread; 32 return buf; 33 } 34 35 int main(void) 36 { 37 printf("=== Bug #8 (FIXED): uart_print/uart_println uncommented ===\n"); 38 39 long size; 40 char *src = read_file(SOURCE_FILE, &size); 41 if (!src) { 42 src = read_file("/Users/ganeshpanth/PLFM_RADAR/9_Firmware/9_1_Microcontroller/9_1_3_C_Cpp_Code/main.cpp", &size); 43 } 44 assert(src != NULL && "Could not open main.cpp"); 45 printf(" Read %ld bytes from main.cpp\n", size); 46 47 /* ---- Test A: uart_print is NOT inside a block comment ---- */ 48 const char *uart_print_sig = "static void uart_print(const char *msg)"; 49 char *pos = strstr(src, uart_print_sig); 50 assert(pos != NULL && "uart_print function signature not found in source"); 51 printf(" Found uart_print signature at offset %ld\n", (long)(pos - src)); 52 53 int inside_comment = 0; 54 for (char *p = src; p < pos; p++) { 55 if (p[0] == '/' && p[1] == '*') { 56 inside_comment = 1; 57 p++; 58 } else if (p[0] == '*' && p[1] == '/') { 59 inside_comment = 0; 60 p++; 61 } 62 } 63 printf(" uart_print is inside block comment: %s\n", 64 inside_comment ? "YES" : "NO"); 65 assert(inside_comment == 0); 66 printf(" PASS: uart_print is NOT commented out (FIXED)\n"); 67 68 /* ---- Test B: uart_println is NOT inside a block comment ---- */ 69 const char *uart_println_sig = "static void uart_println(const char *msg)"; 70 pos = strstr(src, uart_println_sig); 71 assert(pos != NULL && "uart_println function signature not found in source"); 72 printf(" Found uart_println signature at offset %ld\n", (long)(pos - src)); 73 74 inside_comment = 0; 75 for (char *p = src; p < pos; p++) { 76 if (p[0] == '/' && p[1] == '*') { 77 inside_comment = 1; 78 p++; 79 } else if (p[0] == '*' && p[1] == '/') { 80 inside_comment = 0; 81 p++; 82 } 83 } 84 printf(" uart_println is inside block comment: %s\n", 85 inside_comment ? "YES" : "NO"); 86 assert(inside_comment == 0); 87 printf(" PASS: uart_println is NOT commented out (FIXED)\n"); 88 89 free(src); 90 printf("=== Bug #8 (FIXED): ALL TESTS PASSED ===\n\n"); 91 return 0; 92 }