Line data Source code
1 : /**
2 : * @file
3 : *
4 : * @brief Benchmark for get and set of storage plugins
5 : *
6 : * @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
7 : *
8 : */
9 :
10 : #include <stdio.h>
11 :
12 : #include <kdb.h>
13 : #include <kdbhelper.h>
14 : #include <kdbmodule.h>
15 : #include <kdbprivate.h>
16 :
17 0 : int main (int argc, char ** argv)
18 : {
19 0 : if (argc < 4 || argc > 5 || (argc == 5 && elektraStrCmp (argv[4], "get") != 0))
20 : {
21 0 : fprintf (stderr, "Usage: %s <path> <parent> <plugin> [get]\n", argv[0]);
22 0 : return 1;
23 : }
24 :
25 : typedef enum
26 : {
27 : BOTH,
28 : GET
29 : } Direction;
30 :
31 0 : Direction direction = BOTH;
32 0 : if (argc == 5) direction = GET;
33 :
34 0 : const char * path = argv[1];
35 0 : const char * parent = argv[2];
36 0 : const char * pluginname = argv[3];
37 :
38 0 : KeySet * ks = ksNew (0, KS_END);
39 0 : char * infile = elektraFormat ("%s/test.%s.in", path, pluginname);
40 0 : char * outfile = elektraFormat ("%s/test.%s.out", path, pluginname);
41 :
42 : {
43 0 : Key * getKey = keyNew (parent, KEY_VALUE, infile, KEY_END);
44 :
45 0 : KeySet * conf = ksNew (0, KS_END);
46 0 : KeySet * modules = ksNew (0, KS_END);
47 0 : elektraModulesInit (modules, 0);
48 0 : Key * errorKey = keyNew ("", KEY_END);
49 0 : Plugin * plugin = elektraPluginOpen (pluginname, modules, conf, errorKey);
50 0 : keyDel (errorKey);
51 :
52 0 : plugin->kdbGet (plugin, ks, getKey);
53 :
54 0 : keyDel (getKey);
55 0 : elektraPluginClose (plugin, 0);
56 0 : elektraModulesClose (modules, 0);
57 0 : ksDel (modules);
58 : }
59 :
60 0 : if (ksGetSize (ks) <= 0)
61 : {
62 : return 1;
63 : }
64 :
65 0 : if (direction == BOTH)
66 : {
67 0 : Key * setKey = keyNew (parent, KEY_VALUE, outfile, KEY_END);
68 :
69 0 : KeySet * conf = ksNew (0, KS_END);
70 0 : KeySet * modules = ksNew (0, KS_END);
71 0 : elektraModulesInit (modules, 0);
72 0 : Key * errorKey = keyNew ("", KEY_END);
73 0 : Plugin * plugin = elektraPluginOpen (pluginname, modules, conf, errorKey);
74 0 : keyDel (errorKey);
75 0 : plugin->kdbSet (plugin, ks, setKey);
76 :
77 0 : keyDel (setKey);
78 0 : elektraPluginClose (plugin, 0);
79 0 : elektraModulesClose (modules, 0);
80 0 : ksDel (modules);
81 : }
82 :
83 0 : elektraFree (infile);
84 0 : elektraFree (outfile);
85 :
86 0 : ksDel (ks);
87 0 : return 0;
88 : }
|