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) 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 generate_cper_record((char **)types, num_types, stream); 24 fclose(stream); 25 26 //Return fmemopen() buffer for reading. 27 return fmemopen(*buf, *buf_size, "r"); 28 }