END_TEST /** Check that an empty <collect /> sends all streams to that collection point (#1272) */ START_TEST (test_config_empty_collect) { OmlMP *mp; OmlValueU v[2]; char buf[1024]; char config[] = "<omlc domain='check_liboml2_config' id='test_config_empty_collect'>\n" " <collect url='file:test_config_empty_collect' encoding='text' />\n" "</omlc>"; int s1found = 0; FILE *fp; logdebug("%s\n", __FUNCTION__); MAKEOMLCMDLINE(argc, argv, "file:test_config_empty_collect"); argv[1] = "--oml-config"; argv[2] = "test_config_empty_collect.xml"; argc = 3; fp = fopen (argv[2], "w"); fail_unless(fp != NULL, "Could not create configuration file %s: %s", argv[2], strerror(errno)); fail_unless(fwrite(config, sizeof(config), 1, fp) == 1, "Could not write configuration in file %s: %s", argv[2], strerror(errno)); fclose(fp); unlink("test_config_empty_collect"); fail_if(omlc_init(__FUNCTION__, &argc, argv, NULL), "Could not initialise OML"); mp = omlc_add_mp(__FUNCTION__, mp_def); fail_if(mp==NULL, "Could not add MP"); fail_if(omlc_start(), "Could not start OML"); omlc_set_uint32(v[0], 1); omlc_set_uint32(v[1], 2); fail_if(omlc_inject(mp, v), "Injection failed"); omlc_close(); fp = fopen(__FUNCTION__, "r"); fail_unless(fp != NULL, "Output file %s missing", __FUNCTION__); while(fgets(buf, sizeof(buf), fp) && !s1found) { if (!strncmp(buf, "schema: 1", 9)) { s1found = 1; } } fail_unless(s1found, "Schema 1 never defined"); fclose(fp); }
static void test_main(void *param) { int8_t result = omlc_init ("Simple"); if (result == -1) { printf ("Could not initialise OML\n"); while(1); } else if (result == 1) { printf ("OML was disabled by the user, exiting\n"); while(1); } OmlMPDef mp_def [] = { { "count", OML_UINT32_VALUE }, { "count_str", OML_STRING_VALUE }, { "count_real", OML_DOUBLE_VALUE }, { NULL, (OmlValueT)0 } }; OmlMP *mp = omlc_add_mp ("counter", mp_def); if (mp == NULL) { printf ("Error: could not register Measurement Point 'counter'"); while(1); } omlc_start(); uint32_t i = 0; for (i = 0; i < 100; i++) { uint32_t count = i; char count_str[16]; double count_real = (double)i; OmlValueU values[3]; omlc_zero_array(values, 3); snprintf(count_str, sizeof(count_str), "%d", i); omlc_set_uint32 (values[0], count); omlc_set_string (values[1], count_str); omlc_set_double (values[2], count_real); omlc_inject (mp, values); omlc_reset_string(values[1]); } omlc_close(); while(1); }
END_TEST /** Check that multiple <collect /> do not trigger a "Measurement stream 'd_lin' already exists" error (#1154) */ START_TEST (test_config_multi_collect) { OmlMP *mp; OmlValueU v[2]; char buf[1024], *bufp; char *dests[2] = { "test_config_multi_collect1", "test_config_multi_collect2" }; char config[] = "<omlc domain='check_liboml2_config' id='test_config_multi_collect'>\n" " <collect url='file:test_config_multi_collect1' encoding='text' />\n" " <collect url='file:test_config_multi_collect2' encoding='text' />\n" "</omlc>"; int i, s1found = 0, emptyfound = 0, n, datafound[2] = {0, 0}; FILE *fp; logdebug("%s\n", __FUNCTION__); MAKEOMLCMDLINE(argc, argv, "file:test_config_multi_collect"); argv[1] = "--oml-config"; argv[2] = "test_config_multi_collect.xml"; argc = 3; fp = fopen (argv[2], "w"); fail_unless(fp != NULL, "Could not create configuration file %s: %s", argv[2], strerror(errno)); fail_unless(fwrite(config, sizeof(config), 1, fp) == 1, "Could not write configuration in file %s: %s", argv[2], strerror(errno)); fclose(fp); unlink("test_config_multi_collect1"); unlink("test_config_multi_collect2"); fail_if(omlc_init(__FUNCTION__, &argc, argv, NULL), "Could not initialise OML"); mp = omlc_add_mp(__FUNCTION__, mp_def); fail_if(mp==NULL, "Could not add MP"); fail_if(omlc_start(), "Could not start OML"); omlc_set_uint32(v[0], 1); omlc_set_uint32(v[1], 2); fail_if(omlc_inject(mp, v), "Injection failed"); omlc_close(); for (i=0; i<2; i++) { s1found = 0; fp = fopen(dests[i], "r"); fail_unless(fp != NULL, "Output file %s missing", __FUNCTION__); emptyfound = 0; while(fgets(buf, sizeof(buf), fp) && (!s1found || !datafound[i])) { if (!strncmp(buf, "schema: 1", 9)) { s1found = 1; } else if (emptyfound) { /* We know we are passed the header; * We check that the data is here, that is, we have * 5 tab-delimited fields (ts, schemaid, seqno, d1, d2) */ bufp = buf; n = 0; while(++n<6 && strtok(bufp, "\t")) { bufp = NULL; /* Make strtok continue on the same string */ }; if (n==6) { datafound[i] = 1; } } else if (*buf == '\n') { emptyfound = 1; } } fail_unless(s1found, "Schema 1 never defined in %s", dests[i]); fail_unless(datafound[i], "No actual data in %s", dests[i]); fclose(fp); } }