libubox
C utility functions for OpenWrt.
test-blobmsg-parse.c File Reference
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
#include <libgen.h>
#include "blobmsg.h"

Go to the source code of this file.

Macros

#define BUF_LEN   256
 

Enumerations

enum  { FOO_MESSAGE , FOO_LIST , FOO_TESTDATA , __FOO_MAX }
 

Functions

static void dump_result (const char *fn, int r, const char *filename, struct blob_attr **tb)
 
static void test_blobmsg (const char *filename)
 
int main (int argc, char *argv[])
 

Variables

static const struct blobmsg_policy foo_policy []
 

Macro Definition Documentation

◆ BUF_LEN

#define BUF_LEN   256

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
FOO_MESSAGE 
FOO_LIST 
FOO_TESTDATA 
__FOO_MAX 

Definition at line 8 of file test-blobmsg-parse.c.

8  {
10  FOO_LIST,
12  __FOO_MAX
13 };
@ FOO_TESTDATA
@ __FOO_MAX
@ FOO_MESSAGE
@ FOO_LIST

Function Documentation

◆ dump_result()

static void dump_result ( const char *  fn,
int  r,
const char *  filename,
struct blob_attr **  tb 
)
static

Definition at line 30 of file test-blobmsg-parse.c.

31 {
32  fprintf(stdout, "%s: %s: %c%c%c (%d)\n", basename((char *) filename), fn,
33  tb[FOO_MESSAGE] ? 'M' : '.',
34  tb[FOO_LIST] ? 'L' : '.',
35  tb[FOO_TESTDATA] ? 'T' : '.',
36  r);
37 }
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 70 of file test-blobmsg-parse.c.

71 {
72  if (argc != 2) {
73  fprintf(stderr, "Usage: %s <blobmsg.bin>\n", argv[0]);
74  return 3;
75  }
76 
77  test_blobmsg(argv[1]);
78 
79  return 0;
80 }
static void test_blobmsg(const char *filename)
Here is the call graph for this function:

◆ test_blobmsg()

static void test_blobmsg ( const char *  filename)
static

Definition at line 39 of file test-blobmsg-parse.c.

40 {
41 #define BUF_LEN 256
42  int r = 0;
43  size_t len = 0;
44  FILE *fd = NULL;
45  char *buf = NULL;
46  struct blob_attr *tb[__FOO_MAX];
47 
48  fd = fopen(filename, "r");
49  if (!fd) {
50  fprintf(stderr, "unable to open %s\n", filename);
51  return;
52  }
53 
54  buf = malloc(BUF_LEN+1);
55  if (!buf)
56  return;
57 
58  len = fread(buf, 1, BUF_LEN, fd);
59  fclose(fd);
60 
61  r = blobmsg_parse(foo_policy, ARRAY_SIZE(foo_policy), tb, buf, len);
62  dump_result("blobmsg_parse", r, filename, tb);
63 
65  dump_result("blobmsg_parse_array", r, filename, tb);
66 
67  free(buf);
68 }
int blobmsg_parse_array(const struct blobmsg_policy *policy, int policy_len, struct blob_attr **tb, void *data, unsigned int len)
Definition: blobmsg.c:140
int blobmsg_parse(const struct blobmsg_policy *policy, int policy_len, struct blob_attr **tb, void *data, unsigned int len)
Definition: blobmsg.c:166
Definition: blob.h:52
static void dump_result(const char *fn, int r, const char *filename, struct blob_attr **tb)
#define BUF_LEN
static const struct blobmsg_policy foo_policy[]
#define ARRAY_SIZE(x)
FILE(GLOB test_cases "test-*.c") MACRO(ADD_FUZZER_TEST name) ADD_EXECUTABLE($
Definition: CMakeLists.txt:1
int fd
Definition: udebug-priv.h:27
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ foo_policy

const struct blobmsg_policy foo_policy[]
static
Initial value:
= {
.name = "message",
},
[FOO_LIST] = {
.name = "list",
},
.name = "testdata",
},
}
@ BLOBMSG_TYPE_TABLE
Definition: blobmsg.h:28
@ BLOBMSG_TYPE_STRING
Definition: blobmsg.h:29
@ BLOBMSG_TYPE_ARRAY
Definition: blobmsg.h:27

Definition at line 1 of file test-blobmsg-parse.c.