1 /*
2 * Copyright (C) 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <errno.h>
18 #include <stdio.h>
19 #include <string.h>
20
21 /* The main purpose of this test is to ensure this C header compiles in C, so
22 * that no C++ features inadvertently leak into the C ABI. */
23 #include "art_api/dex_file_external.h"
24
25 static const char gtest_output_arg[] = "--gtest_output=xml:";
26 static const char gtest_output_xml[] = "\
27 <?xml version=\"1.0\"?>\n\
28 <testsuites tests=\"0\" failures=\"0\" disabled=\"0\" errors=\"0\" name=\"AllTests\">";
29
30 /* Writes a dummy gtest xml report to the given path. */
write_gtest_output_xml(char * gtest_output_path)31 static int write_gtest_output_xml(char* gtest_output_path) {
32 FILE* output_fd = fopen(gtest_output_path, "w");
33 if (output_fd == NULL) {
34 fprintf(stderr, "Failed to open %s: %s\n", gtest_output_path, strerror(errno));
35 return 1;
36 }
37 if (fprintf(output_fd, gtest_output_xml) != sizeof(gtest_output_xml) - 1) {
38 fprintf(stderr, "Failed to write %s: %s\n", gtest_output_path, strerror(errno));
39 fclose(output_fd);
40 return 1;
41 }
42 if (fclose(output_fd) != 0) {
43 fprintf(stderr, "Failed to close %s: %s\n", gtest_output_path, strerror(errno));
44 return 1;
45 }
46 return 0;
47 }
48
main(int argc,char ** argv)49 int main(int argc, char** argv) {
50 if (argc >= 2 && strncmp(argv[1], gtest_output_arg, sizeof(gtest_output_arg) - 1) == 0) {
51 /* The ART gtest framework expects all tests to understand --gtest_output. */
52 return write_gtest_output_xml(argv[1] + sizeof(gtest_output_arg) - 1);
53 }
54 return 0;
55 }
56