blob: 3837030d39586889c7deed88b2551b4eef02c143 [file] [log] [blame]
Lawrence Tangd34f2b12022-07-19 15:36:31 +01001/**
2 * Defines utility functions for testing CPER-JSON IR output from the cper-parse library.
Ed Tanousfedd4572024-07-12 13:56:00 -07003 *
Lawrence Tangd34f2b12022-07-19 15:36:31 +01004 * Author: Lawrence.Tang@arm.com
5 **/
6
John Chungf8fc7052024-05-03 20:05:29 +08007#include <cstdio>
8#include <cstdlib>
Lawrence Tangd34f2b12022-07-19 15:36:31 +01009#include "test-utils.hpp"
10extern "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.
Lawrence Tange407b4c2022-07-21 13:54:01 +010016FILE *generate_record_memstream(const char **types, UINT16 num_types,
John Chungf8fc7052024-05-03 20:05:29 +080017 char **buf, size_t *buf_size,
18 int single_section)
Lawrence Tangd34f2b12022-07-19 15:36:31 +010019{
Lawrence Tange407b4c2022-07-21 13:54:01 +010020 //Open a memory stream.
21 FILE *stream = open_memstream(buf, buf_size);
Lawrence Tangd34f2b12022-07-19 15:36:31 +010022
Lawrence Tange407b4c2022-07-21 13:54:01 +010023 //Generate a section to the stream, close & return.
John Chungf8fc7052024-05-03 20:05:29 +080024 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 }
Lawrence Tange407b4c2022-07-21 13:54:01 +010031 fclose(stream);
Lawrence Tangd34f2b12022-07-19 15:36:31 +010032
Lawrence Tange407b4c2022-07-21 13:54:01 +010033 //Return fmemopen() buffer for reading.
34 return fmemopen(*buf, *buf_size, "r");
John Chungf8fc7052024-05-03 20:05:29 +080035}