2 * Copyright (c) 2008-2009 Apple Inc. All rights reserved.
4 * @APPLE_APACHE_LICENSE_HEADER_START@
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * @APPLE_APACHE_LICENSE_HEADER_END@
21 #include "config/config.h"
28 has_prefix(const char* str, const char* prefix) {
29 return (strncmp(str, prefix, strlen(prefix)) == 0);
33 print_summary(FILE* f, long total, long pass, long fail) {
34 fprintf(f, "Total: %ld\n", total);
35 fprintf(f, "Passed: %ld (%0.0lf%%)\n", pass, ((double)pass / (double)total) * (double)100.0);
36 fprintf(f, "Failed: %ld (%0.0lf%%)\n", fail, ((double)fail / (double)total) * (double)100.0);
41 int main(int argc, char* argv[]) {
43 fprintf(stderr, "%s: usage: summarize\n", argv[0]);
48 FILE* f = fopen(argv[1], "w");
56 fprintf(f, "\n==================================================\n");
57 fprintf(f, "[SUMMARY] Test Summary\n");
58 fprintf(f, "==================================================\n\n");
69 ln = fgetln(stdin, &len);
70 //if (ln) fprintf(stdout, "%.*s", (int)len, ln);
71 if (ln == NULL || has_prefix(ln, "[TEST]")) {
73 print_summary(f, total, pass, fail);
82 fprintf(f, "%.*s", (int)len, ln);
84 fprintf(f, "[TOTAL]\n");
85 print_summary(f, total_total, total_pass, total_fail);
88 } else if (has_prefix(ln, "[PASS]")) {
91 } else if (has_prefix(ln, "[FAIL]")) {
97 return (total_fail ? EXIT_FAILURE : EXIT_SUCCESS);