Related: rhbz#1938800 Fix CI tests and convert them to tmt

This commit is contained in:
Mike FABIAN 2021-06-21 09:47:56 +02:00
parent 34b1d3fa01
commit 78658bb28b
10 changed files with 75 additions and 152 deletions

1
.fmf/version Normal file
View File

@ -0,0 +1 @@
1

View File

@ -1,6 +1,6 @@
# This spec file has been automatically updated
Version: 0.9.10
Release: 13%{?dist}
Release: 14%{?dist}
Name: libunistring
Summary: GNU Unicode string library
License: GPLv2+ or LGPLv3+
@ -56,6 +56,9 @@ mv $RPM_BUILD_ROOT%{_datadir}/doc/%{name} __doc
%ldconfig_scriptlets
%changelog
* Mon Jun 21 2021 Mike FABIAN <mfabian@redhat.com> - 0.9.10-14
- Related rhbz#1938800: Fix CI tests and convert them to tmt
* Mon Jun 14 2021 Mike FABIAN <mfabian@redhat.com> - 0.9.10-13
- Related rhbz#1938800: Fix spelling in license GPLV2+ -> GPLv2+

5
plans/basic.fmf Normal file
View File

@ -0,0 +1,5 @@
summary: Basic smoke test
discover:
how: fmf
execute:
how: tmt

2
tests/libunistring-tests/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
test
testfile.utf*

View File

@ -1,61 +0,0 @@
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Makefile of /CoreOS/python/libunistring-tests
# Description: Functional tests for libunistring.
# Author: Pooja Yadav <poyadav@redhat.com>
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Copyright (c) 2015 Red Hat, Inc.
#
# This program is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 2 of
# the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
export TEST=/CoreOS/python/libunistring-tests
export TESTVERSION=1.0
BUILT_FILES=
FILES=$(METADATA) libunistring_test.py Makefile test runtest.sh
.PHONY: all install download clean
run: $(FILES) build
./runtest.sh
build: $(BUILT_FILES)
test -x runtest.sh || chmod a+x runtest.sh
clean:
rm -f *~ $(BUILT_FILES)
$(METADATA): Makefile
@echo "Owner: Pooja Yadav <poyadav@redhat.com>" > $(METADATA)
@echo "Name: $(TEST)" >> $(METADATA)
@echo "TestVersion: $(TESTVERSION)" >> $(METADATA)
@echo "Path: $(TEST_DIR)" >> $(METADATA)
@echo "Description: Functional test for the gettext module" >> $(METADATA)
@echo "Type: Sanity" >> $(METADATA)
@echo "TestTime: 5m" >> $(METADATA)
@echo "RunFor: python" >> $(METADATA)
@echo "Requires: python" >> $(METADATA)
@echo "Priority: Normal" >> $(METADATA)
@echo "License: GPLv2" >> $(METADATA)
@echo "Confidential: no" >> $(METADATA)
@echo "Destructive: no" >> $(METADATA)
rhts-lint $(METADATA)

View File

@ -1,10 +1,11 @@
# -*- coding: utf-8 -*-
import sys
import os
import subprocess
import logging
"""
"""
Creating a result.log file for saving logs
"""
logging.basicConfig(level=logging.INFO)
@ -13,67 +14,45 @@ logging.info("TEST RESULTS FOR <uniconv.h> FUNCTION\n\n")
data = []
def create_testfile():
testfile = subprocess.call("./test 'Bonjour le monde'" , shell=True)
with open("./testfile.in") as fh:
lines = fh.readlines()
global data
data = lines
TESTTEXT = 'Viele Grüße\n日本語\n'
def test_utf8():
def create_testfiles():
dummy = subprocess.run("./test '" + TESTTEXT + "'", shell=True)
def test(path='', encoding=''):
"""
Check UTF-8 encoding
Read the file at path using the specified encoding and check
whether the TESTTEXT can be read back correctly.
"""
logging.info('Testing file %s using encoding %s', path, encoding)
try:
conv8 = data[0].strip("\n").decode('utf-8')
conv16 = data[0].strip("\n").decode('utf-16')
if conv8 == ("Bonjour le monde") and conv16 != ("Bonjour le monde"):
logging.info("UTF-8 Conversion Test: SUCCESS")
with open(path, mode='rt', encoding=encoding) as testfile:
text = testfile.read()
logging.info('TESTTEXT="%s", text read ="%s"\n', TESTTEXT, text)
if text == TESTTEXT:
logging.info(
'testfile: %s testencoding: %s Read test: SUCCESS',
path, encoding)
else:
logging.error("UTF-8 Conversion Test: ERROR")
logging.info(
'testfile: %s testencoding: %s Read test: ERROR',
path, encoding)
except UnicodeError:
logging.error("UTF-8 Conversion Test: UnicodeError")
def test_utf_16():
"""
Check UTF-16 encoding
"""
try:
conv16 = data[1].strip("\n").decode('utf-16')
conv8 = data[1].strip("\n").decode('utf-8')
if conv16 == ("Bonjour le monde") and conv8 != ("Bonjour le monde"):
logging.info("UTF-16 Conversion Test: SUCCESS")
else:
logging.error("UTF-16 Conversion Test: ERROR")
except UnicodeError:
logging.error("UTF-16 Conversion Test: UnicodeError")
def test_utf_32():
"""
Check UTF-32 encoding
"""
try:
conv8 = data[2].strip("\n").decode('utf-8')
conv16= data[2].strip("\n").decode('utf-16')
conv32 = data[2].strip("\n").decode('utf-32')
if conv32 == ("Bonjour le monde") and conv8 and conv16 != ("Bonjour le monde"):
logging.info("UTF-32 Conversion Test: SUCCESS")
else:
logging.error("UTF-32 Conversion Test: ERROR")
except UnicodeError:
logging.error("UTF-32 Conversion Test: UnicodeError")
def del_testfile():
try:
subprocess.call(['rm', '-rf', './testfile.in'])
except OSError as e:
logging.error("OSError\n")
if __name__ == "__main__":
del_testfile()
create_testfile()
test_utf8()
test_utf_16()
test_utf_32()
if sys.byteorder == 'little':
endianness = 'le'
else:
endianness = 'be'
testfiles = {
'testfile.utf-8': 'utf-8',
'testfile.utf-16': 'utf-16' + endianness,
'testfile.utf-32': 'utf-32' + endianness,
}
for testfile in testfiles:
if os.path.isfile(testfile):
os.unlink(testfile)
create_testfiles()
for testfile in testfiles:
test(path=testfile, encoding=testfiles[testfile])

View File

@ -0,0 +1,16 @@
summary: Functional test for the gettext module
contact: Pooja Yadav <poyadav@redhat.com>
component:
- python
require:
- gcc
- make
- libunistring
- libunistring-devel
test: bash runtest.sh
framework: beakerlib
recommend:
- python
duration: 5m
extra-summary: /CoreOS/python/libunistring-tests
extra-task: /CoreOS/python/libunistring-tests

4
tests/libunistring-tests/runtest.sh Normal file → Executable file
View File

@ -27,14 +27,14 @@
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Include Beaker environment
. /usr/bin/rhts-environment.sh
. /usr/lib/beakerlib/beakerlib.sh
. /usr/share/beakerlib/beakerlib.sh || exit 1
PACKAGE="libunistring"
rlJournalStart
rlPhaseStartSetup
rlAssertRpm $PACKAGE
rlRun "gcc test.c -lunistring -o test"
rlRun "TmpDir=\`mktemp -d\`" 0 "Creating tmp directory"
rlRun "cp libunistring_test.py test $TmpDir"
rlRun "pushd $TmpDir"

View File

@ -15,23 +15,24 @@ main (int argc, char **argv)
}
size_t len8, len16, len32;
const char newline = '\n';
uint8_t *res8 = u8_conv_from_encoding ("ASCII", iconveh_question_mark, argv[1], strlen (argv[1]), NULL, NULL, &len8);
uint16_t *res16 = u16_conv_from_encoding ("ASCII", iconveh_question_mark, argv[1], strlen (argv[1]), NULL, NULL, &len16);
uint32_t *res32 = u32_conv_from_encoding ("ASCII", iconveh_question_mark, argv[1], strlen (argv[1]), NULL, NULL, &len32);
int fd = open ("testfile.in", O_WRONLY | O_CREAT, S_IRUSR);
uint8_t *res8 = u8_conv_from_encoding ("UTF-8", iconveh_question_mark, argv[1], strlen (argv[1]), NULL, NULL, &len8);
uint16_t *res16 = u16_conv_from_encoding ("UTF-8", iconveh_question_mark, argv[1], strlen (argv[1]), NULL, NULL, &len16);
uint32_t *res32 = u32_conv_from_encoding ("UTF-8", iconveh_question_mark, argv[1], strlen (argv[1]), NULL, NULL, &len32);
int fd = open ("testfile.utf-8", O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
for (int i = 0; i < len8; i++)
write (fd, &res8[i], sizeof (uint8_t));
write (fd, &newline, 1);
close (fd);
fd = open ("testfile.utf-16", O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
for (int i = 0; i < len16; i++)
write (fd, &res16[i], sizeof (uint16_t));
write (fd, &newline, 1);
close (fd);
fd = open ("testfile.utf-32", O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
for (int i = 0; i < len32; i++)
write (fd, &res32[i], sizeof (uint32_t));
close (fd);
}

View File

@ -1,23 +0,0 @@
---
# Tests for Atomic
- hosts: localhost
tags:
- atomic
roles:
- role: standard-test-beakerlib
tests:
- libunistring-tests
# Tests for Classic and Container
- hosts: localhost
tags:
- classic
- container
roles:
- role: standard-test-beakerlib
tests:
- libunistring-tests
required_packages:
- libunistring
- libunistring-devel