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 extern "C" {
11 #include "../edk/BaseTypes.h"
12 #include "../generator/cper-generate.h"
13 }
14
15 //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)16 FILE *generate_record_memstream(const char **types, UINT16 num_types,
17 char **buf, size_t *buf_size,
18 int single_section)
19 {
20 //Open a memory stream.
21 FILE *stream = open_memstream(buf, buf_size);
22
23 //Generate a section to the stream, close & return.
24 if (!single_section) {
25 generate_cper_record(const_cast<char **>(types), num_types,
26 stream);
27 } else {
28 generate_single_section_record(const_cast<char *>(types[0]),
29 stream);
30 }
31 fclose(stream);
32
33 //Return fmemopen() buffer for reading.
34 return fmemopen(*buf, *buf_size, "r");
35 }
36