Lawrence Tang | d34f2b1 | 2022-07-19 15:36:31 +0100 | [diff] [blame] | 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, char** buf, size_t* buf_size) |
| 17 | { |
| 18 | //Open a memory stream. |
| 19 | FILE* stream = open_memstream(buf, buf_size); |
| 20 | |
| 21 | //Generate a section to the stream, close & return. |
| 22 | generate_cper_record((char**)types, num_types, stream); |
| 23 | fclose(stream); |
| 24 | |
| 25 | //Return fmemopen() buffer for reading. |
| 26 | return fmemopen(*buf, *buf_size, "r"); |
| 27 | } |