1 /**
2 * Defines utility functions for testing CPER-JSON IR output from the cper-parse library.
3 *
4 * Author: Lawrence.Tang@arm.com
5 **/
6
7 #include <cstdio>
8 #include <cstdlib>
9 #include "test-utils.hpp"
10
11 #include "BaseTypes.h"
12 #include "../generator/cper-generate.h"
13
14 //Returns a ready-for-use memory stream containing a CPER record with the given sections inside.
generate_record_memstream(const char ** types,UINT16 num_types,char ** buf,size_t * buf_size,int single_section)15 FILE *generate_record_memstream(const char **types, UINT16 num_types,
16 char **buf, size_t *buf_size,
17 int single_section)
18 {
19 //Open a memory stream.
20 FILE *stream = open_memstream(buf, buf_size);
21
22 //Generate a section to the stream, close & return.
23 if (!single_section) {
24 generate_cper_record(const_cast<char **>(types), num_types,
25 stream);
26 } else {
27 generate_single_section_record(const_cast<char *>(types[0]),
28 stream);
29 }
30 fclose(stream);
31
32 //Return fmemopen() buffer for reading.
33 return fmemopen(*buf, *buf_size, "r");
34 }
35