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 <stdio.h> 8 #include <stdlib.h> 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. 16 FILE *generate_record_memstream(const char **types, UINT16 num_types, 17 char **buf, size_t *buf_size, 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((char **)types, num_types, stream); 25 else 26 generate_single_section_record((char*)types[0], stream); 27 fclose(stream); 28 29 //Return fmemopen() buffer for reading. 30 return fmemopen(*buf, *buf_size, "r"); 31 }