+enum field_type {
+ FIELD_TYPE_PAYLOAD,
+ FIELD_TYPE_CONTEXT,
+ FIELD_TYPE_APP_CONTEXT,
+ FIELD_TYPE_ARRAY_FIELD,
+};
+
+struct capture_base_field_tuple {
+ char* field_name;
+ enum field_type field_type;
+ /* Do we expect a userspace capture? */
+ bool expected_ust;
+ /* Do we expect a kernel capture? */
+ bool expected_kernel;
+ validate_cb validate_ust;
+ validate_cb validate_kernel;
+};
+
+static
+const char *field_value_type_to_str(enum lttng_event_field_value_type type)
+{
+ switch (type) {
+ case LTTNG_EVENT_FIELD_VALUE_TYPE_UNKNOWN:
+ return "UNKNOWN";
+ case LTTNG_EVENT_FIELD_VALUE_TYPE_INVALID:
+ return "INVALID";
+ case LTTNG_EVENT_FIELD_VALUE_TYPE_UNSIGNED_INT:
+ return "UNSIGNED INT";
+ case LTTNG_EVENT_FIELD_VALUE_TYPE_SIGNED_INT:
+ return "SIGNED INT";
+ case LTTNG_EVENT_FIELD_VALUE_TYPE_UNSIGNED_ENUM:
+ return "UNSIGNED ENUM";
+ case LTTNG_EVENT_FIELD_VALUE_TYPE_SIGNED_ENUM:
+ return "SIGNED ENUM";
+ case LTTNG_EVENT_FIELD_VALUE_TYPE_REAL:
+ return "REAL";
+ case LTTNG_EVENT_FIELD_VALUE_TYPE_STRING:
+ return "STRING";
+ case LTTNG_EVENT_FIELD_VALUE_TYPE_ARRAY:
+ return "ARRAY";
+ default:
+ abort();
+ }
+}
+
+static int validate_type(const struct lttng_event_field_value *event_field,
+ enum lttng_event_field_value_type expect)
+{
+ int ret;
+ enum lttng_event_field_value_type value;
+
+ value = lttng_event_field_value_get_type(event_field);
+ if (value == LTTNG_EVENT_FIELD_VALUE_TYPE_INVALID) {
+ ret = 1;
+ goto end;
+ }
+
+ ok(expect == value, "Expected field type %s, got %s",
+ field_value_type_to_str(expect),
+ field_value_type_to_str(value));
+
+ ret = expect != value;
+
+end:
+ return ret;
+}
+
+/*
+ * Validate unsigned captured field against the iteration number.
+ */
+static int validate_unsigned_int_field(
+ const struct lttng_event_field_value *event_field,
+ unsigned int expected_value)
+{
+ int ret;
+ uint64_t value;
+ enum lttng_event_field_value_status status;
+
+ ret = validate_type(
+ event_field, LTTNG_EVENT_FIELD_VALUE_TYPE_UNSIGNED_INT);
+ if (ret) {
+ goto end;
+ }
+
+ status = lttng_event_field_value_unsigned_int_get_value(
+ event_field, &value);
+ if (status != LTTNG_EVENT_FIELD_VALUE_STATUS_OK) {
+ fail("lttng_event_field_value_unsigned_int_get_value returned an error: status = %d",
+ (int) status);
+ ret = 1;
+ goto end;
+ }
+
+ ok(value == (uint64_t) expected_value,
+ "Expected unsigned integer value %u, got %" PRIu64,
+ expected_value, value);
+
+ ret = value != (uint64_t) expected_value;
+
+end:
+ return ret;
+}
+
+/*
+ * Validate signed captured field.
+ */
+static int validate_signed_int_field(
+ const struct lttng_event_field_value *event_field,
+ unsigned int iteration)
+{
+ int ret;
+ const int64_t expected = -1;
+ int64_t value;
+ enum lttng_event_field_value_status status;
+
+ /* Unused. */
+ (void) iteration;
+
+ ret = validate_type(
+ event_field, LTTNG_EVENT_FIELD_VALUE_TYPE_SIGNED_INT);
+ if (ret) {
+ goto end;
+ }
+
+ status = lttng_event_field_value_signed_int_get_value(
+ event_field, &value);
+ if (status != LTTNG_EVENT_FIELD_VALUE_STATUS_OK) {
+ fail("lttng_event_field_value_signed_int_get_value returned an error: status = %d",
+ (int) status);
+ ret = 1;
+ goto end;
+ }
+
+ ok(value == expected,
+ "Expected signed integer value %" PRId64
+ ", got %" PRId64,
+ expected, value);
+
+ ret = value != expected;
+
+end:
+
+ return ret;
+}
+
+/*
+ * Validate array of unsigned int.
+ */
+static int validate_array_unsigned_int_field(
+ const struct lttng_event_field_value *event_field,
+ unsigned int iteration)
+{
+ int ret;
+ enum lttng_event_field_value_status status;
+ const unsigned int expected = 3;
+ unsigned int i, count;
+
+ /* Unused. */
+ (void) iteration;
+
+ ret = validate_type(event_field, LTTNG_EVENT_FIELD_VALUE_TYPE_ARRAY);
+ if (ret) {
+ goto end;
+ }
+
+ status = lttng_event_field_value_array_get_length(event_field, &count);
+ if (status != LTTNG_EVENT_FIELD_VALUE_STATUS_OK) {
+ fail("lttng_event_field_value_array_get_length");
+ ret = 1;
+ goto end;
+ }
+
+ ok(count == expected, "Expected %d subelements, got %d", expected,
+ count);
+ if (count != expected) {
+ ret = 1;
+ goto end;
+ }
+
+ for (i = 1; i < count + 1; i++) {
+ const struct lttng_event_field_value *value;
+
+ status = lttng_event_field_value_array_get_element_at_index(
+ event_field, i - 1, &value);
+ if (status != LTTNG_EVENT_FIELD_VALUE_STATUS_OK) {
+ fail("lttng_event_field_value_array_get_element_at_index returned an error: status = %d",
+ (int) status);
+ ret = 1;
+ goto end;
+ }
+
+ ret = validate_unsigned_int_field(value, i);
+ if (ret) {
+ goto end;
+ }
+ }
+
+ ret = 0;
+end:
+
+ return ret;
+}
+
+static int validate_array_unsigned_int_field_at_index(
+ const struct lttng_event_field_value *event_field,
+ unsigned int iteration)
+{
+ int ret;
+ const uint64_t expected_value = 2;
+ enum lttng_event_field_value_status status;
+ uint64_t value;
+
+ /* Unused. */
+ (void) iteration;
+
+ ret = validate_type(
+ event_field, LTTNG_EVENT_FIELD_VALUE_TYPE_UNSIGNED_INT);
+ if (ret) {
+ goto end;
+ }
+
+ status = lttng_event_field_value_unsigned_int_get_value(
+ event_field, &value);
+ if (status != LTTNG_EVENT_FIELD_VALUE_STATUS_OK) {
+ fail("lttng_event_field_value_unsigned_int_get_value returned an error: status = %d",
+ (int) status);
+ ret = 1;
+ goto end;
+ }
+
+ ok(value == expected_value,
+ "Expected unsigned integer value %u, got %" PRIu64,
+ expected_value, value);
+
+ ret = 0;
+end:
+ return ret;
+}
+
+/*
+ * Validate sequence for a string (seqfield1):
+ *
+ * Value: "test" encoded in UTF-8: [116, 101, 115, 116]
+ */
+static int validate_seqfield1(const struct lttng_event_field_value *event_field,
+ unsigned int iteration)
+{
+ int ret;
+ enum lttng_event_field_value_status status;
+ unsigned int i, count;
+ const unsigned int expect[] = {116, 101, 115, 116};
+ const size_t array_count = sizeof(expect) / sizeof(*expect);
+
+ /* Unused. */
+ (void) iteration;
+
+ ret = validate_type(event_field, LTTNG_EVENT_FIELD_VALUE_TYPE_ARRAY);
+ if (ret) {
+ goto end;
+ }
+
+ status = lttng_event_field_value_array_get_length(event_field, &count);
+ if (status != LTTNG_EVENT_FIELD_VALUE_STATUS_OK) {
+ fail("lttng_event_field_value_array_get_length returned an error: status = %d",
+ (int) status);
+ ret = 1;
+ goto end;
+ }
+
+ ok(count == array_count, "Expected %zu array sub-elements, got %d",
+ array_count, count);
+ if (count != array_count) {
+ ret = 1;
+ goto end;
+ }
+
+ for (i = 0; i < count; i++) {
+ const struct lttng_event_field_value *value;
+
+ status = lttng_event_field_value_array_get_element_at_index(
+ event_field, i, &value);
+ if (status != LTTNG_EVENT_FIELD_VALUE_STATUS_OK) {
+ fail("lttng_event_field_value_array_get_element_at_index returned an error: status = %d",
+ (int) status);
+ ret = 1;
+ goto end;
+ }
+
+ ret = validate_unsigned_int_field(value, expect[i]);
+ if (ret) {
+ goto end;
+ }
+ }
+
+ ret = 0;
+end:
+ return ret;
+}
+
+static int validate_string(
+ const struct lttng_event_field_value *event_field,
+ const char *expect)
+{
+ int ret;
+ const char *value = NULL;
+ enum lttng_event_field_value_status status;
+
+ ret = validate_type(event_field, LTTNG_EVENT_FIELD_VALUE_TYPE_STRING);
+ if (ret) {
+ goto end;
+ }
+
+ status = lttng_event_field_value_string_get_value(event_field, &value);
+ if (!value) {
+ fail("lttng_event_field_value_array_get_length returned an error: status = %d",
+ (int) status);
+ ret = 1;
+ goto end;
+ }
+
+ ok(!strcmp(value, expect), "Expected string value \"%s\", got \"%s\"",
+ expect, value);
+
+ ret = 0;
+end:
+
+ return ret;
+}
+
+/*
+ * Validate string. Expected value is "test".
+ */
+static int validate_string_test(
+ const struct lttng_event_field_value *event_field,
+ unsigned int iteration)
+{
+ const char * const expect = "test";
+
+ /* Unused. */
+ (void) iteration;
+
+ return validate_string(event_field, expect);
+}
+
+/*
+ * Validate escaped string. Expected value is "\*".
+ */
+static int validate_string_escaped(
+ const struct lttng_event_field_value *event_field,
+ unsigned int iteration)
+{
+ const char * const expect = "\\*";
+
+ /* Unused. */
+ (void) iteration;
+
+ return validate_string(event_field, expect);
+}
+
+/*
+ * Validate real field.
+ */
+static int validate_real(
+ const struct lttng_event_field_value *event_field,
+ double expect)
+{
+ int ret;
+ double value;
+ enum lttng_event_field_value_status status;
+
+ ret = validate_type(event_field, LTTNG_EVENT_FIELD_VALUE_TYPE_REAL);
+ if (ret) {
+ goto end;
+ }
+
+ status = lttng_event_field_value_real_get_value(event_field, &value);
+ if (status != LTTNG_EVENT_FIELD_VALUE_STATUS_OK) {
+ fail("lttng_event_field_value_real_get_value returned an error: status = %d",
+ (int) status);
+ ret = 1;
+ goto end;
+ }
+
+ ok(value == expect, "Expected real value %f, got %f", expect, value);
+ ret = value != expect;
+end:
+ return ret;
+}
+
+/*
+ * Validate floatfield.
+ */
+static int validate_floatfield(
+ const struct lttng_event_field_value *event_field,
+ unsigned int iteration)
+{
+ const double expect = 2222.0;
+
+ /* Unused. */
+ (void) iteration;
+
+ return validate_real(event_field, expect);
+}
+
+/*
+ * Validate doublefield.
+ */
+static int validate_doublefield(
+ const struct lttng_event_field_value *event_field,
+ unsigned int iteration)
+{
+ const double expect = 2.0;
+
+ /* Unused. */
+ (void) iteration;
+
+ return validate_real(event_field, expect);
+}
+
+/*
+ * Validate enum0: enum0 = ( "AUTO: EXPECT 0" : container = 0 )
+ */
+static int validate_enum0(const struct lttng_event_field_value *event_field,
+ unsigned int iteration)
+{
+ int ret;
+ enum lttng_event_field_value_status status;
+ uint64_t value;
+ const uint64_t expected_value = 0;
+
+ /* Unused. */
+ (void) iteration;
+
+ ret = validate_type(event_field,
+ LTTNG_EVENT_FIELD_VALUE_TYPE_UNSIGNED_ENUM);
+ if (ret) {
+ goto end;
+ }
+
+ status = lttng_event_field_value_unsigned_int_get_value(
+ event_field, &value);
+ if (status != LTTNG_EVENT_FIELD_VALUE_STATUS_OK) {
+ fail("lttng_event_field_value_unsigned_int_get_value returned an error: status = %d",
+ (int) status);
+ ret = 1;
+ goto end;
+ }
+
+ ok(value == expected_value,
+ "Expected enum value %" PRIu64 ", got %" PRIu64,
+ expected_value, value);
+
+end:
+ return ret;
+}
+
+/*
+ * Validate enumnegative: enumnegative = ( "AUTO: EXPECT 0" : container = 0 )
+ *
+ * We expect 2 labels here.
+ */
+static int validate_enumnegative(
+ const struct lttng_event_field_value *event_field,
+ unsigned int iteration)
+{
+ int ret;
+ enum lttng_event_field_value_status status;
+ int64_t value;
+ const int64_t expected_value = -1;
+
+ /* Unused. */
+ (void) iteration;
+
+ ret = validate_type(event_field,
+ LTTNG_EVENT_FIELD_VALUE_TYPE_SIGNED_ENUM);
+ if (ret) {
+ goto end;
+ }
+
+ status = lttng_event_field_value_signed_int_get_value(
+ event_field, &value);
+ if (status != LTTNG_EVENT_FIELD_VALUE_STATUS_OK) {
+ fail("lttng_event_field_value_unsigned_int_get_value");
+ ret = 1;
+ goto end;
+ }
+
+ ok(value == expected_value,
+ "Expected enum value %" PRId64 ", got %" PRId64,
+ expected_value, value);
+
+end:
+ return ret;
+}
+
+static int validate_context_procname_ust(
+ const struct lttng_event_field_value *event_field,
+ unsigned int iteration)
+{
+ /* Unused. */
+ (void) iteration;
+ return validate_string(event_field, "gen-ust-events");
+}
+
+static int validate_context_procname_kernel(
+ const struct lttng_event_field_value *event_field,
+ unsigned int iteration)
+{
+ /* Unused. */
+ (void) iteration;
+ return validate_string(event_field, "echo");
+}
+
+struct capture_base_field_tuple test_capture_base_fields[] = {
+ { "DOESNOTEXIST", FIELD_TYPE_PAYLOAD, false, false, NULL, NULL },
+ { "intfield", FIELD_TYPE_PAYLOAD, true, true, validate_unsigned_int_field, validate_unsigned_int_field },
+ { "longfield", FIELD_TYPE_PAYLOAD, true, true, validate_unsigned_int_field, validate_unsigned_int_field },
+ { "signedfield", FIELD_TYPE_PAYLOAD, true, true, validate_signed_int_field, validate_signed_int_field },
+ { "arrfield1", FIELD_TYPE_PAYLOAD, true, true, validate_array_unsigned_int_field, validate_array_unsigned_int_field },
+ { "arrfield2", FIELD_TYPE_PAYLOAD, true, true, validate_string_test, validate_string_test },
+ { "arrfield3", FIELD_TYPE_PAYLOAD, true, true, validate_array_unsigned_int_field, validate_array_unsigned_int_field },
+ { "seqfield1", FIELD_TYPE_PAYLOAD, true, true, validate_seqfield1, validate_seqfield1 },
+ { "seqfield2", FIELD_TYPE_PAYLOAD, true, true, validate_string_test, validate_string_test },
+ { "seqfield3", FIELD_TYPE_PAYLOAD, true, true, validate_array_unsigned_int_field, validate_array_unsigned_int_field },
+ { "seqfield4", FIELD_TYPE_PAYLOAD, true, true, validate_array_unsigned_int_field, validate_array_unsigned_int_field },
+ { "arrfield1[1]", FIELD_TYPE_ARRAY_FIELD, true, true, validate_array_unsigned_int_field_at_index, validate_array_unsigned_int_field_at_index },
+ { "stringfield", FIELD_TYPE_PAYLOAD, true, true, validate_string_test, validate_string_test },
+ { "stringfield2", FIELD_TYPE_PAYLOAD, true, true, validate_string_escaped, validate_string_escaped },
+ { "floatfield", FIELD_TYPE_PAYLOAD, true, false, validate_floatfield, validate_floatfield },
+ { "doublefield", FIELD_TYPE_PAYLOAD, true, false, validate_doublefield, validate_doublefield },
+ { "enum0", FIELD_TYPE_PAYLOAD, true, true, validate_enum0, validate_enum0 },
+ { "enumnegative", FIELD_TYPE_PAYLOAD, true, true, validate_enumnegative, validate_enumnegative },
+ { "$ctx.procname", FIELD_TYPE_CONTEXT, true, true, validate_context_procname_ust, validate_context_procname_kernel },
+};
+
+static const char *get_notification_trigger_name(
+ struct lttng_notification *notification)
+{
+ const char *name = NULL;
+ enum lttng_evaluation_status status;
+ const struct lttng_evaluation *evaluation;
+ evaluation = lttng_notification_get_evaluation(notification);
+ if (evaluation == NULL) {
+ fail("lttng_notification_get_evaluation");
+ goto end;
+ }
+
+ switch (lttng_evaluation_get_type(evaluation)) {
+ case LTTNG_CONDITION_TYPE_ON_EVENT:
+ {
+ status = lttng_evaluation_on_event_get_trigger_name(
+ evaluation, &name);
+ if (status != LTTNG_EVALUATION_STATUS_OK) {
+ fail("lttng_evaluation_on_event_get_trigger_name");
+ name = NULL;
+ goto end;
+ }
+ break;
+ }
+ default:
+ fail("Wrong notification evaluation type \n");
+ goto end;
+ }
+end:
+ return name;
+}
+
+static int validator_notification_trigger_name(
+ struct lttng_notification *notification,
+ const char *trigger_name)
+{
+ int ret;
+ bool name_is_equal;
+ const char *name;
+
+ assert(notification);
+ assert(trigger_name);
+
+ name = get_notification_trigger_name(notification);
+ if (name == NULL) {
+ ret = 1;
+ goto end;
+ }
+
+ name_is_equal = (strcmp(trigger_name, name) == 0);
+ ok(name_is_equal, "Expected trigger name: %s got %s", trigger_name,
+ name);
+
+ ret = !name_is_equal;
+
+end:
+ return ret;
+}
+