libubox
C utility functions for OpenWrt.
test-blobmsg-procd-instance.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stdint.h>
3 #include <stddef.h>
4 #include <libgen.h>
5 
6 #include "blobmsg.h"
7 #include "utils.h"
8 
9 enum {
34 };
35 
36 static const struct blobmsg_policy instance_attr[__INSTANCE_ATTR_MAX] = {
37  [INSTANCE_ATTR_COMMAND] = { "command", BLOBMSG_TYPE_ARRAY },
39  [INSTANCE_ATTR_DATA] = { "data", BLOBMSG_TYPE_TABLE },
40  [INSTANCE_ATTR_NETDEV] = { "netdev", BLOBMSG_TYPE_ARRAY },
41  [INSTANCE_ATTR_FILE] = { "file", BLOBMSG_TYPE_ARRAY },
42  [INSTANCE_ATTR_TRIGGER] = { "triggers", BLOBMSG_TYPE_ARRAY },
43  [INSTANCE_ATTR_RESPAWN] = { "respawn", BLOBMSG_TYPE_ARRAY },
44  [INSTANCE_ATTR_NICE] = { "nice", BLOBMSG_TYPE_INT32 },
45  [INSTANCE_ATTR_LIMITS] = { "limits", BLOBMSG_TYPE_TABLE },
46  [INSTANCE_ATTR_WATCH] = { "watch", BLOBMSG_TYPE_ARRAY },
47  [INSTANCE_ATTR_ERROR] = { "error", BLOBMSG_TYPE_ARRAY },
50  [INSTANCE_ATTR_STDOUT] = { "stdout", BLOBMSG_TYPE_BOOL },
51  [INSTANCE_ATTR_STDERR] = { "stderr", BLOBMSG_TYPE_BOOL },
52  [INSTANCE_ATTR_NO_NEW_PRIVS] = { "no_new_privs", BLOBMSG_TYPE_BOOL },
53  [INSTANCE_ATTR_JAIL] = { "jail", BLOBMSG_TYPE_TABLE },
54  [INSTANCE_ATTR_TRACE] = { "trace", BLOBMSG_TYPE_BOOL },
55  [INSTANCE_ATTR_SECCOMP] = { "seccomp", BLOBMSG_TYPE_STRING },
56  [INSTANCE_ATTR_PIDFILE] = { "pidfile", BLOBMSG_TYPE_STRING },
57  [INSTANCE_ATTR_RELOADSIG] = { "reload_signal", BLOBMSG_TYPE_INT32 },
58  [INSTANCE_ATTR_TERMTIMEOUT] = { "term_timeout", BLOBMSG_TYPE_INT32 },
59  [INSTANCE_ATTR_FACILITY] = { "facility", BLOBMSG_TYPE_STRING },
60 };
61 
62 static void test_blobmsg_procd_instance(const char *filename)
63 {
64 #define BUF_LEN 2048
65  int r = 0;
66  size_t len = 0;
67  FILE *fd = NULL;
68  char *buf = NULL;
69  struct blob_attr *tb[__INSTANCE_ATTR_MAX];
70  const char *fname = basename((char *) filename);
71 
72  fd = fopen(filename, "r");
73  if (!fd) {
74  fprintf(stderr, "unable to open %s\n", fname);
75  return;
76  }
77 
78  buf = malloc(BUF_LEN+1);
79  if (!buf)
80  return;
81 
82  len = fread(buf, 1, BUF_LEN, fd);
83  fclose(fd);
84 
86  if (r)
87  goto out;
88 
90  goto out;
91 
93  goto out;
94 
95  if (blobmsg_get_u32(tb[INSTANCE_ATTR_NICE]) != 19)
96  goto out;
97 
99  goto out;
100 
101  fprintf(stderr, "%s: OK\n", fname);
102 out:
103  free(buf);
104 }
105 
106 int main(int argc, char *argv[])
107 {
108  if (argc != 2) {
109  fprintf(stderr, "Usage: %s <blobmsg.bin>\n", argv[0]);
110  return 3;
111  }
112 
114 
115  return 0;
116 }
bool blobmsg_check_attr_list(const struct blob_attr *attr, int type)
Definition: blobmsg.c:130
int blobmsg_parse(const struct blobmsg_policy *policy, int policy_len, struct blob_attr **tb, void *data, unsigned int len)
Definition: blobmsg.c:166
static uint32_t blobmsg_get_u32(struct blob_attr *attr)
Definition: blobmsg.h:293
@ BLOBMSG_TYPE_TABLE
Definition: blobmsg.h:28
@ BLOBMSG_TYPE_STRING
Definition: blobmsg.h:29
@ BLOBMSG_TYPE_BOOL
Definition: blobmsg.h:34
@ BLOBMSG_TYPE_ARRAY
Definition: blobmsg.h:27
@ BLOBMSG_TYPE_INT32
Definition: blobmsg.h:31
static bool blobmsg_get_bool(struct blob_attr *attr)
Definition: blobmsg.h:283
Definition: blob.h:52
int main(int argc, char *argv[])
static void test_blobmsg_procd_instance(const char *filename)
static const struct blobmsg_policy instance_attr[__INSTANCE_ATTR_MAX]
#define BUF_LEN
@ INSTANCE_ATTR_TERMTIMEOUT
@ INSTANCE_ATTR_NO_NEW_PRIVS
@ INSTANCE_ATTR_RELOADSIG
@ INSTANCE_ATTR_FACILITY
FILE(GLOB test_cases "test-*.c") MACRO(ADD_FUZZER_TEST name) ADD_EXECUTABLE($
Definition: CMakeLists.txt:1
int fd
Definition: udebug-priv.h:27