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