From 206fead2178c65e208e5b93223cc9855566b0dfb Mon Sep 17 00:00:00 2001 From: Adrian Reber Date: Wed, 23 Feb 2022 22:32:01 +0100 Subject: [PATCH] Added gating tests Related: rhbz#2057348 Signed-off-by: Adrian Reber --- gating.yaml | 6 ++++ protobuf-c.spec | 5 +++- tests/Makefile | 11 +++++++ tests/add_person.c | 63 ++++++++++++++++++++++++++++++++++++++++ tests/addressbook.proto | 43 +++++++++++++++++++++++++++ tests/run-simple-test.sh | 10 +++++++ tests/tests.yml | 16 ++++++++++ 7 files changed, 153 insertions(+), 1 deletion(-) create mode 100644 gating.yaml create mode 100644 tests/Makefile create mode 100644 tests/add_person.c create mode 100644 tests/addressbook.proto create mode 100755 tests/run-simple-test.sh create mode 100644 tests/tests.yml diff --git a/gating.yaml b/gating.yaml new file mode 100644 index 0000000..648918d --- /dev/null +++ b/gating.yaml @@ -0,0 +1,6 @@ +--- !Policy +product_versions: + - rhel-9 +decision_context: osci_compose_gate +rules: + - !PassingTestCaseRule {test_case_name: osci.brew-build.tier0.functional} diff --git a/protobuf-c.spec b/protobuf-c.spec index 92c7eee..4479c3f 100644 --- a/protobuf-c.spec +++ b/protobuf-c.spec @@ -1,6 +1,6 @@ Name: protobuf-c Version: 1.3.3 -Release: 10%{?dist} +Release: 11%{?dist} Summary: C bindings for Google's Protocol Buffers License: BSD @@ -66,6 +66,9 @@ rm -vf $RPM_BUILD_ROOT/%{_libdir}/libprotobuf-c.la %{_libdir}/pkgconfig/libprotobuf-c.pc %changelog +* Wed Feb 23 2022 Adrian Reber - 1.3.3-11 +- Added gating tests + * Wed Feb 23 2022 Adrian Reber - 1.3.3-10 - Rebuilt for errata diff --git a/tests/Makefile b/tests/Makefile new file mode 100644 index 0000000..0af6954 --- /dev/null +++ b/tests/Makefile @@ -0,0 +1,11 @@ +all: add_person_c + +protoc_middleman: addressbook.proto + protoc-c --c_out=. addressbook.proto + +add_person_c: add_person.c protoc_middleman + pkg-config --libs libprotobuf-c # fails if protobuf is not installed + gcc add_person.c addressbook.pb-c.c -o add_person_c `pkg-config --libs libprotobuf-c` + +clean: + rm -f add_person_c addressbook.pb-c.c addressbook.pb-c.h diff --git a/tests/add_person.c b/tests/add_person.c new file mode 100644 index 0000000..d56e4ee --- /dev/null +++ b/tests/add_person.c @@ -0,0 +1,63 @@ +// Based on the examples from protobuf-c + +#include "addressbook.pb-c.h" +#include +#include +#include + +int main(void) +{ + Foo__Person__PhoneNumber__Comment comment = FOO__PERSON__PHONE_NUMBER__COMMENT__INIT; + Foo__Person__PhoneNumber phone = FOO__PERSON__PHONE_NUMBER__INIT; + Foo__Person__PhoneNumber *phone_numbers[1]; + Foo__Person person = FOO__PERSON__INIT; + Foo__Person *person2; + unsigned char simple_pad[8]; + size_t size, size2; + unsigned char *packed; + ProtobufCBufferSimple bs = PROTOBUF_C_BUFFER_SIMPLE_INIT(simple_pad); + + comment.comment = "protobuf-c guy"; + + phone.number = "1234"; + phone.has_type = 1; + phone.type = FOO__PERSON__PHONE_TYPE__WORK; + phone.comment = &comment; + + phone_numbers[0] = ☎ + + person.name = "dave b"; + person.id = 42; + person.n_phone = 1; + person.phone = phone_numbers; + + size = foo__person__get_packed_size(&person); + packed = malloc(size); + assert(packed); + + size2 = foo__person__pack(&person, packed); + + assert(size == size2); + foo__person__pack_to_buffer(&person, &bs.base); + assert(bs.len == size); + assert(memcmp(bs.data, packed, size) == 0); + + PROTOBUF_C_BUFFER_SIMPLE_CLEAR(&bs); + + person2 = foo__person__unpack(NULL, size, packed); + assert(person2 != NULL); + assert(person2->id == 42); + assert(person2->email == NULL); + assert(strcmp(person2->name, "dave b") == 0); + assert(person2->n_phone == 1); + assert(strcmp(person2->phone[0]->number, "1234") == 0); + assert(strcmp(person2->phone[0]->comment->comment, "protobuf-c guy") == 0); + assert(person2->phone[0]->type == FOO__PERSON__PHONE_TYPE__WORK); + + foo__person__free_unpacked(person2, NULL); + free(packed); + + printf("test succeeded.\n"); + + return 0; +} diff --git a/tests/addressbook.proto b/tests/addressbook.proto new file mode 100644 index 0000000..3506690 --- /dev/null +++ b/tests/addressbook.proto @@ -0,0 +1,43 @@ +syntax = "proto2"; +package foo; + +import "protobuf-c/protobuf-c.proto"; + +option (pb_c_file).c_package = "foo"; + +message Person +{ + required string name = 1; + required int32 id = 2; + optional string email = 3; + + enum PhoneType { + MOBILE = 0; + HOME = 1; + WORK = 2; + } + + message PhoneNumber + { + message Comment + { + required string comment = 1; + } + + required string number = 1; + optional PhoneType type = 2 [default = HOME]; + optional Comment comment = 3; + } + + repeated PhoneNumber phone = 4; +} + +message LookupResult +{ + optional Person person = 1; +} + +message Name +{ + optional string name = 1; +}; diff --git a/tests/run-simple-test.sh b/tests/run-simple-test.sh new file mode 100755 index 0000000..9777f79 --- /dev/null +++ b/tests/run-simple-test.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +set -ex +uname -a + +make clean all + +./add_person_c +make clean +exit 0 diff --git a/tests/tests.yml b/tests/tests.yml new file mode 100644 index 0000000..00aff9d --- /dev/null +++ b/tests/tests.yml @@ -0,0 +1,16 @@ +--- +- hosts: localhost + roles: + - role: standard-test-basic + tags: + - classic + required_packages: + - make + - gcc + - protobuf-c-devel + - protobuf-c-compiler + - pkgconf-pkg-config + tests: + - simple: + dir: . + run: ./run-simple-test.sh