blob: e16413c6c001e8a0d4f43b27394ba775a2559338 [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"
Karthik Rajagopalan255bd812024-09-06 14:36:34 -070010
Thu Nguyene42fb482024-10-15 14:43:11 +000011#include <libcper/BaseTypes.h>
12#include <libcper/generator/cper-generate.h>
Lawrence Tangd34f2b12022-07-19 15:36:31 +010013
14//Returns a ready-for-use memory stream containing a CPER record with the given sections inside.
Lawrence Tange407b4c2022-07-21 13:54:01 +010015FILE *generate_record_memstream(const char **types, UINT16 num_types,
John Chungf8fc7052024-05-03 20:05:29 +080016 char **buf, size_t *buf_size,
17 int single_section)
Lawrence Tangd34f2b12022-07-19 15:36:31 +010018{
Lawrence Tange407b4c2022-07-21 13:54:01 +010019 //Open a memory stream.
20 FILE *stream = open_memstream(buf, buf_size);
Lawrence Tangd34f2b12022-07-19 15:36:31 +010021
Lawrence Tange407b4c2022-07-21 13:54:01 +010022 //Generate a section to the stream, close & return.
John Chungf8fc7052024-05-03 20:05:29 +080023 if (!single_section) {
24 generate_cper_record(const_cast<char **>(types), num_types,
25 stream);
26 } else {
27 generate_single_section_record(const_cast<char *>(types[0]),
28 stream);
29 }
Lawrence Tange407b4c2022-07-21 13:54:01 +010030 fclose(stream);
Lawrence Tangd34f2b12022-07-19 15:36:31 +010031
Lawrence Tange407b4c2022-07-21 13:54:01 +010032 //Return fmemopen() buffer for reading.
33 return fmemopen(*buf, *buf_size, "r");
John Chungf8fc7052024-05-03 20:05:29 +080034}