| 1 | /* |
| 2 | * ctf-parser-test.c |
| 3 | * |
| 4 | * Common Trace Format Parser Test |
| 5 | * |
| 6 | * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 7 | * |
| 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 9 | * of this software and associated documentation files (the "Software"), to deal |
| 10 | * in the Software without restriction, including without limitation the rights |
| 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 12 | * copies of the Software, and to permit persons to whom the Software is |
| 13 | * furnished to do so, subject to the following conditions: |
| 14 | * |
| 15 | * The above copyright notice and this permission notice shall be included in |
| 16 | * all copies or substantial portions of the Software. |
| 17 | */ |
| 18 | |
| 19 | #include <stdlib.h> |
| 20 | #include <stdio.h> |
| 21 | #include <glib.h> |
| 22 | #include <errno.h> |
| 23 | #include <babeltrace/endian.h> |
| 24 | #include <babeltrace/babeltrace-internal.h> |
| 25 | #include <babeltrace/ctf/metadata.h> |
| 26 | #include "ctf-scanner.h" |
| 27 | #include "ctf-parser.h" |
| 28 | #include "ctf-ast.h" |
| 29 | |
| 30 | int babeltrace_verbose, babeltrace_debug; |
| 31 | |
| 32 | int main(int argc, char **argv) |
| 33 | { |
| 34 | struct ctf_scanner *scanner; |
| 35 | struct ctf_trace *trace; |
| 36 | int ret = 0; |
| 37 | |
| 38 | babeltrace_debug = 1; |
| 39 | babeltrace_verbose = 1; |
| 40 | scanner = ctf_scanner_alloc(stdin); |
| 41 | if (!scanner) { |
| 42 | fprintf(stderr, "Error allocating scanner\n"); |
| 43 | return -ENOMEM; |
| 44 | } |
| 45 | ret = ctf_scanner_append_ast(scanner); |
| 46 | if (ret) { |
| 47 | fprintf(stderr, "Error creating AST\n"); |
| 48 | goto end; |
| 49 | } |
| 50 | |
| 51 | ret = ctf_visitor_print_xml(stderr, 0, &scanner->ast->root); |
| 52 | if (ret) { |
| 53 | fprintf(stderr, "Error visiting AST for XML output\n"); |
| 54 | goto end; |
| 55 | } |
| 56 | |
| 57 | ret = ctf_visitor_semantic_check(stderr, 0, &scanner->ast->root); |
| 58 | if (ret) { |
| 59 | fprintf(stderr, "Error in CTF semantic validation %d\n", ret); |
| 60 | goto end; |
| 61 | } |
| 62 | trace = malloc(sizeof(*trace)); |
| 63 | memset(trace, 0, sizeof(*trace)); |
| 64 | ret = ctf_visitor_construct_metadata(stderr, 0, &scanner->ast->root, |
| 65 | trace, BYTE_ORDER); |
| 66 | if (ret) { |
| 67 | fprintf(stderr, "Error in CTF metadata constructor %d\n", ret); |
| 68 | goto free_trace; |
| 69 | } |
| 70 | free_trace: |
| 71 | free(trace); |
| 72 | end: |
| 73 | ctf_scanner_free(scanner); |
| 74 | return ret; |
| 75 | } |