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