Commit | Line | Data |
---|---|---|
c59a87f5 MD |
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 | ||
34d3acc4 MD |
19 | #include <stdlib.h> |
20 | #include <stdio.h> | |
21 | #include <glib.h> | |
67905e42 | 22 | #include <errno.h> |
43e34335 | 23 | #include <babeltrace/endian.h> |
70bd0a12 | 24 | #include <babeltrace/babeltrace-internal.h> |
78af2bcd | 25 | #include <babeltrace/ctf/metadata.h> |
34d3acc4 MD |
26 | #include "ctf-scanner.h" |
27 | #include "ctf-parser.h" | |
28 | #include "ctf-ast.h" | |
29 | ||
a3983482 | 30 | int babeltrace_verbose, babeltrace_debug; |
34d3acc4 MD |
31 | |
32 | int main(int argc, char **argv) | |
33 | { | |
34 | struct ctf_scanner *scanner; | |
78af2bcd | 35 | struct ctf_trace *trace; |
7de8808c | 36 | int ret = 0; |
34d3acc4 | 37 | |
a3983482 | 38 | babeltrace_debug = 1; |
c8b219a3 | 39 | babeltrace_verbose = 1; |
34d3acc4 MD |
40 | scanner = ctf_scanner_alloc(stdin); |
41 | if (!scanner) { | |
3394d22e | 42 | fprintf(stderr, "Error allocating scanner\n"); |
67905e42 | 43 | return -ENOMEM; |
34d3acc4 | 44 | } |
8a4035bc MD |
45 | ret = ctf_scanner_append_ast(scanner); |
46 | if (ret) { | |
3394d22e | 47 | fprintf(stderr, "Error creating AST\n"); |
8a4035bc MD |
48 | goto end; |
49 | } | |
7de8808c | 50 | |
3394d22e | 51 | ret = ctf_visitor_print_xml(stderr, 0, &scanner->ast->root); |
67905e42 | 52 | if (ret) { |
3394d22e | 53 | fprintf(stderr, "Error visiting AST for XML output\n"); |
67905e42 | 54 | goto end; |
7de8808c | 55 | } |
7de8808c | 56 | |
3394d22e | 57 | ret = ctf_visitor_semantic_check(stderr, 0, &scanner->ast->root); |
67905e42 | 58 | if (ret) { |
3394d22e | 59 | fprintf(stderr, "Error in CTF semantic validation %d\n", ret); |
67905e42 MD |
60 | goto end; |
61 | } | |
78af2bcd | 62 | trace = malloc(sizeof(*trace)); |
34e5b91e | 63 | memset(trace, 0, sizeof(*trace)); |
3394d22e | 64 | ret = ctf_visitor_construct_metadata(stderr, 0, &scanner->ast->root, |
78af2bcd MD |
65 | trace, BYTE_ORDER); |
66 | if (ret) { | |
3394d22e | 67 | fprintf(stderr, "Error in CTF metadata constructor %d\n", ret); |
78af2bcd MD |
68 | goto free_trace; |
69 | } | |
70 | free_trace: | |
71 | free(trace); | |
67905e42 MD |
72 | end: |
73 | ctf_scanner_free(scanner); | |
7de8808c | 74 | return ret; |
34d3acc4 | 75 | } |