| 76 | |
| 77 | |
| 78 | static int |
| 79 | testGen(void) |
| 80 | { |
| 81 | char buf[4096]; |
| 82 | char name[64]; |
| 83 | int r; |
| 84 | struct KgenContext *ctx; |
| 85 | size_t s; |
| 86 | |
| 87 | ctx = createKgenContext(buf, sizeof(buf), true); |
| 88 | if (ctx == NULL) { |
| 89 | printf("Context creation failed\n"); |
| 90 | printf("FAIL\n\n"); |
| 91 | return -1; |
| 92 | } |
| 93 | |
| 94 | printf("Test normal kernel generation\n"); |
| 95 | if (!testGenFunc(ctx)) { |
| 96 | printf("Generated code:\n\n"); |
| 97 | printf("%s", buf); |
| 98 | printf("\n\nPASS\n\n"); |
| 99 | } |
| 100 | else { |
| 101 | printf("FAIL\n\n"); |
| 102 | } |
| 103 | |
| 104 | printf("Test function name extracting from the generated code\n"); |
| 105 | r = kgenGetLastFuncName(name, sizeof(name), ctx); |
| 106 | if (r) { |
| 107 | printf("FAIL\n"); |
| 108 | } |
| 109 | else { |
| 110 | if (strcmp((const char*)name, "strcpy")) { |
| 111 | printf("Extracted names is %s must be strcpy\n", name); |
| 112 | printf("FAIL\n\n"); |
| 113 | r = -1; |
| 114 | } |
| 115 | else { |
| 116 | printf("PASS\n\n"); |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | destroyKgenContext(ctx); |
| 121 | |
| 122 | printf("Test source size calculating without actual source " |
| 123 | "adding to any buffer\n"); |
| 124 | ctx = createKgenContext(NULL, 0, true); |
| 125 | r = kgenAddStmt(ctx, strcpyImpl); |
| 126 | if (!r) { |
| 127 | s = kgenSourceSize(ctx); |
| 128 | if (s != strlen(strcpyImpl)) { |
| 129 | r = -1; |
| 130 | } |
| 131 | } |
| 132 | if (r) { |
| 133 | printf("FAIL\n\n"); |
| 134 | } |
| 135 | else { |
no test coverage detected