Travis functional testing & minor changes

This commit is contained in:
Brendan LE GLAUNEC
2016-11-23 06:38:59 +01:00
committed by Brendan Le Glaunec
parent 2961d68200
commit fbd78301a0
22 changed files with 188 additions and 173 deletions
+25 -9
View File
@@ -3,6 +3,9 @@ sudo: required
dist: trusty
before_install:
- echo "Testing Docker Hub credentials"
- docker login -u=$DOCKER_USERNAME -p=$DOCKER_PASSWORD
- echo "Docker Hub credentials are working"
- sudo apt-get update -qq
- sudo apt-get install -y software-properties-common
- sudo add-apt-repository -y ppa:mc3man/trusty-media
@@ -19,24 +22,37 @@ before_install:
- sudo apt-get install -y libmysqlclient18
- sudo apt-get install -y mysql-client
install:
- export DEPS_DIR="${TRAVIS_BUILD_DIR}/deps"
- export PACKAGE_NAME="cameradar_*_Debug_Linux"
matrix:
include:
- os: linux
env: COMPILER_NAME=gcc CXX=g++-5 CC=gcc-5 CMAKE_CXX_COMPILER=g++-5
env: TEST_TYPE='BUILD' WORKDIR='deployment' COMPILER_NAME=gcc CXX=g++-5 CC=gcc-5 CMAKE_CXX_COMPILER=g++-5
addons:
apt:
packages:
- g++-5
sources: &sources
- ubuntu-toolchain-r-test
- os: linux
env: TEST_TYPE='TEST' WORKDIR='test' COMPILER_NAME=gcc CXX=g++-5 CC=gcc-5 CMAKE_CXX_COMPILER=g++-5
addons:
apt:
packages:
- g++-5
sources: &sources
- llvm-toolchain-precise-3.8
- ubuntu-toolchain-r-test
script:
- cd deployment
- cd ${WORKDIR}
- ./build_last_package.sh Debug
- tar xvf cameradar_*_Debug_Linux.tar.gz
- cp /home/travis/build/EtixLabs/cameradar/deps/jsoncpp/src/deps.jsoncpp/src/lib_json/libjsoncpp*.so* cameradar_*_Debug_Linux/libraries/
- cp /home/travis/build/EtixLabs/cameradar/deps/mysql-connector/lib/libmysqlcppconn.so* cameradar_*_Debug_Linux/libraries/
- tar -czvf cameradar_*_Debug_Linux.tar.gz cameradar_*_Debug_Linux
- docker build -t cameradar .
- docker run -v /tmp/thumbs:/tmp/thumbs cameradar
- tar xvf ${PACKAGE_NAME}.tar.gz
- find ${DEPS_DIR} -name "*.so*" -exec cp {} ${PACKAGE_NAME}/libraries \;
- tar -czvf ${PACKAGE_NAME}.tar.gz ${PACKAGE_NAME}
- if [[ "$TEST_TYPE" == "BUILD" ]]; then docker build -t cameradar . && docker run -v /tmp/thumbs:/tmp/thumbs cameradar; else ./test.sh ; fi
after_success:
- echo "Test Success - Branch($TRAVIS_BRANCH) Pull Request($TRAVIS_PULL_REQUEST) Tag($TRAVIS_TAG)"
- if [[ "$TRAVIS_BRANCH" == "master" ]]; then echo -e "Push Container to Docker Hub" && docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD && docker tag cameradar $DOCKER_REPO:latest && docker push $DOCKER_REPO; fi
+14
View File
@@ -2,6 +2,20 @@
This file lists all versions of the repository and precises all changes.
## v1.1.3
#### Minor changes :
* Added automatic pushes to DockerHub to the travis integration
* Made travis configuration file better
* Changed the package generation scripts to make them report errors
* Removed old etix_rtsp_server binary from the test folder
#### Bugfixes :
* Fixed an issue that made it mandatory to launch tests at least once so that they can work the second time
* Fixed an issue that made the golang testing tool not compile in the testing script
* Fixed an issue that made the golang testing tool sometimes ignore some tests
* The previous known issue has been investigated and we don't know where it came from. However after a night of testing I have been unable to reproduce it, so I will consider it closed
## v1.1.2
#### Minor changes :
+1 -1
View File
@@ -21,7 +21,7 @@ project (${PROJECT_NAME})
set (${PROJECT_NAME}_VERSION_MAJOR 1)
set (${PROJECT_NAME}_VERSION_MINOR 1)
set (${PROJECT_NAME}_VERSION_PATCH 2)
set (${PROJECT_NAME}_VERSION_PATCH 3)
set (${PROJECT_NAME}_VERSION "${${PROJECT_NAME}_VERSION_MAJOR}.${${PROJECT_NAME}_VERSION_MINOR}.${${PROJECT_NAME}_VERSION_PATCH}${${PROJECT_NAME}_SUFFIX}")
find_package(Git REQUIRED)
+1 -1
View File
@@ -5,7 +5,7 @@
[![cameradar License](https://img.shields.io/badge/license-Apache-blue.svg?style=flat-square)](#license)
[![Docker Pulls](https://img.shields.io/docker/pulls/ullaakut/cameradar.svg?style=flat-square)](https://hub.docker.com/r/ullaakut/cameradar/)
[![Build](https://img.shields.io/travis/EtixLabs/cameradar/master.svg?style=flat-square)](https://travis-ci.org/EtixLabs/cameradar)
[![Latest release](https://img.shields.io/badge/release-1.1.2-green.svg?style=flat-square)](https://github.com/EtixLabs/cameradar/releases/latest)
[![Latest release](https://img.shields.io/badge/release-1.1.3-green.svg?style=flat-square)](https://github.com/EtixLabs/cameradar/releases/latest)
#### Cameradar allows you to:
+1
View File
@@ -25,6 +25,7 @@ size_t
write_data(void* buffer, size_t size, size_t nmemb, void* userp) {
// I'm sorry for this
// Forget you ever saw it
(void)userp;
if (not buffer || not size || not nmemb) return 0;
return size * nmemb;
+41 -11
View File
@@ -5,21 +5,51 @@ COL_RESET=$ESC_SEQ"39;49;00m"
COL_RED=$ESC_SEQ"31;01m"
COL_GREEN=$ESC_SEQ"32;01m"
COL_YELLOW=$ESC_SEQ"33;01m"
COL_BLUE=$ESC_SEQ"34;01m"
COL_MAGENTA=$ESC_SEQ"35;01m"
COL_CYAN=$ESC_SEQ"36;01m"
echo -e $COL_YELLOW"Deleting old package ... "$COL_RESET
rm -f cameradar_*_${1:-"Release"}_Linux.tar.gz
echo -e $COL_GREEN"OK!"$COL_RESET
echo -e $COL_YELLOW"Creating package ... "$COL_RESET
cd ..
mkdir build
cd build
rm -f cameradar_*_${1:-"Release"}_Linux.tar.gz
cmake .. -DCMAKE_BUILD_TYPE=${1:-"Release"}
make package
cp cameradar_*_${1:-"Release"}_Linux.tar.gz ../deployment
cd ../deployment
cd ..
ret=$?
if [ "$ret" -ne "0" ]; then
echo -e $COL_RED"KO!"$COL_RESET;
exit 1;
fi
mkdir build
cd build
ret=$?
if [ "$ret" -ne "0" ]; then
echo -e $COL_RED"KO!"$COL_RESET;
exit 1;
fi
rm -f cameradar_*_${1:-"Release"}_Linux.tar.gz
cmake .. -DCMAKE_BUILD_TYPE=${1:-"Release"}
ret=$?
if [ "$ret" -ne "0" ]; then
echo -e $COL_RED"KO!"$COL_RESET;
exit 1;
fi
make package
ret=$?
if [ "$ret" -ne "0" ]; then
echo -e $COL_RED"KO!"$COL_RESET;
exit 1;
fi
cp cameradar_*_${1:-"Release"}_Linux.tar.gz ../deployment
cd ../deployment
ret=$?
if [ "$ret" -ne "0" ]; then
echo -e $COL_RED"KO!"$COL_RESET;
exit 1;
fi
echo -e $COL_GREEN"OK!"$COL_RESET
Binary file not shown.
Binary file not shown.
+42 -14
View File
@@ -5,23 +5,51 @@ COL_RESET=$ESC_SEQ"39;49;00m"
COL_RED=$ESC_SEQ"31;01m"
COL_GREEN=$ESC_SEQ"32;01m"
COL_YELLOW=$ESC_SEQ"33;01m"
COL_BLUE=$ESC_SEQ"34;01m"
COL_MAGENTA=$ESC_SEQ"35;01m"
COL_CYAN=$ESC_SEQ"36;01m"
echo -e $COL_YELLOW"Deleting old package ... "$COL_RESET
rm -f cameradar_*_Debug_Linux.tar.gz
rm -f cameradar_*_${1:-"Release"}_Linux.tar.gz
echo -e $COL_GREEN"OK!"$COL_RESET
echo -e $COL_YELLOW"Creating package ... "$COL_RESET
{
cd ..
mkdir build
cd build
rm -f cameradar_*_Debug_Linux.tar.gz
cmake .. -DCMAKE_BUILD_TYPE=Debug
make package
cp cameradar_*_Debug_Linux.tar.gz ../test
cd ../test
} &> /dev/null
cd ..
ret=$?
if [ "$ret" -ne "0" ]; then
echo -e $COL_RED"KO!"$COL_RESET;
exit 1;
fi
mkdir build
cd build
ret=$?
if [ "$ret" -ne "0" ]; then
echo -e $COL_RED"KO!"$COL_RESET;
exit 1;
fi
rm -f cameradar_*_${1:-"Release"}_Linux.tar.gz
cmake .. -DCMAKE_BUILD_TYPE=${1:-"Release"}
ret=$?
if [ "$ret" -ne "0" ]; then
echo -e $COL_RED"KO!"$COL_RESET;
exit 1;
fi
make package
ret=$?
if [ "$ret" -ne "0" ]; then
echo -e $COL_RED"KO!"$COL_RESET;
exit 1;
fi
cp cameradar_*_${1:-"Release"}_Linux.tar.gz ../test
cd ../test
ret=$?
if [ "$ret" -ne "0" ]; then
echo -e $COL_RED"KO!"$COL_RESET;
exit 1;
fi
echo -e $COL_GREEN"OK!"$COL_RESET
Binary file not shown.
+6
View File
@@ -14,6 +14,12 @@ cp /tmp/tests/*.xml ./
# run test
./cameradartest /tmp/tests/cameradartest.conf.json
ret=$?
echo "Tests exited with code ${ret}"
cat *.xml
cp *.xml /tmp/tests/
exit $ret
+6 -1
View File
@@ -13,5 +13,10 @@ else
url="rtsp://$user:$passw@:$port/$route"
fi
./camera_emulation_server -u $2 -p $3 -r $4
if [ "$2" == "" && "$3" == "" ]; then
./camera_emulation_server -r $4
else
./camera_emulation_server -u $2 -p $3 -r $4
fi
echo "Stream started on ${url}"
Binary file not shown.
+1 -1
View File
@@ -43,7 +43,7 @@ func (t *Tester) dropDB() bool {
if err != nil {
fmt.Println(err)
}
fmt.Println("------ Dropped CCTV Database -------")
fmt.Println("------ Dropped Cameradar Database -------")
return true
}
-24
View File
@@ -1,24 +0,0 @@
package main
import (
"database/sql"
_ "github.com/go-sql-driver/mysql"
"fmt"
"strconv"
)
func (m *manager) dropDB() bool {
dsn := m.DB.User + ":" + m.DB.Password + "@" + "tcp(" + m.DB.Host + ":" + strconv.Itoa(m.DB.Port) + ")/" + m.DB.Db_name + "?charset=utf8"
db, err := sql.Open("mysql", dsn)
if err != nil {
fmt.Println(err)
}
defer db.Close()
q := "DROP DATABASE cctv;"
_, err = db.Exec(q)
if err != nil {
fmt.Println(err)
}
fmt.Println("------ Dropped CCTV Database -------")
return true
}
-24
View File
@@ -1,24 +0,0 @@
package main
import (
"encoding/json"
"fmt"
"os"
)
// Launch it via goroutine
// Start read log of service
func getResult(test *[]Result, resultPath string) bool {
// Load config
resultFile, err := os.Open(resultPath)
if err != nil {
fmt.Printf("\nCan't open result file: %s\n", err)
return false
}
dec := json.NewDecoder(resultFile)
if err = dec.Decode(&test); err != nil {
fmt.Printf("\nUnable to deserialize result file: %s\n", err)
return false
}
return true
}
+3 -1
View File
@@ -16,6 +16,7 @@ package main
import (
"fmt"
"os"
)
func main() {
@@ -38,7 +39,8 @@ func main() {
fmt.Println("--- Writing results... ---")
if !Tester.WriteResults(*(Tester.Result), Tester.Output) {
fmt.Println("-> Write results FAILED")
return
os.Exit(1)
}
fmt.Println("--- Writing results done ---")
os.Exit(0)
}
-55
View File
@@ -1,55 +0,0 @@
package main
import (
"fmt"
"sync"
)
type manager struct {
Config
Tests []Result
Result *TestCase
DB mysql_db
}
// Config needs refacto
type Config struct {
Cameradar Service `json:"Cameradar"`
Output string
}
func (m *manager) Init() bool {
fmt.Println("- Parsing")
if !m.parseConfig() {
return false
}
fmt.Println("- Cleaning content")
killService(&m.Config.Cameradar)
return true
}
func (m *manager) Run() bool {
var wg sync.WaitGroup
fmt.Println("\n- Launching all tests")
var newTest = new(TestCase)
newTest.expected = m.Tests
if m.generateConfig(m.Tests, &m.DB) {
m.dropDB()
wg.Add(1)
go m.invokeTestCase(newTest, &wg)
m.Result = newTest
}
wg.Wait()
fmt.Printf("All tests completed\n")
return true
}
func (m *manager) Stop() bool {
killService(&m.Config.Cameradar)
return true
}
+1 -1
View File
@@ -55,7 +55,7 @@ func getResult(test *[]Result, resultPath string) bool {
return true
}
func isValid(e Result, r Result) bool {
func isValid(e *Result, r Result) bool {
if e.Username != r.Username {
e.err = errors.New(e.Address + " had a different username than " + r.Username)
return false
+15 -8
View File
@@ -28,6 +28,13 @@ type Test struct {
time time.Duration
}
func removeResult(expected []Result, index int) []Result {
if len(expected) > 1 {
return append(expected[:index], expected[index+1:]...)
}
return []Result{}
}
// Invoke the test
// Wrap results in a TestResult object
func (t *Tester) invokeTestCase(testCase *Test, wg *sync.WaitGroup) {
@@ -55,14 +62,12 @@ func (t *Tester) runTestCase(test *Test) {
for _, r := range test.result {
r.Valid = true
for index, e := range test.expected {
if e.Address == r.Address && isValid(e, r) {
if e.Address == r.Address && isValid(&e, r) {
// _, err := os.Stat(r.Thumb)
// if err == nil) {
fmt.Println("The result of ", r.Address, " is valid and the thumbnails were generated by Cameradar.")
validResults = Extend(validResults, r)
if len(test.expected) > 1 {
test.expected = append(test.expected[:index], test.expected[index+1:]...)
}
test.expected = removeResult(test.expected, index)
break
// } else {
// e.err = error{"The result of " + e.Address + " seemed valid, but the thumbnails could not be generated by Cameradar : " + err.Error()}
@@ -70,15 +75,17 @@ func (t *Tester) runTestCase(test *Test) {
}
}
}
for index, e := range test.expected {
// This is in order to avoid checking the same values twice
copy := test.expected
for index, e := range copy {
if !e.Valid {
fmt.Println("The result of", e.Address, "successfully failed.")
validResults = Extend(validResults, e)
if len(test.expected) > 1 {
test.expected = append(test.expected[:index], test.expected[index+1:]...)
}
test.expected = removeResult(test.expected, index)
} else {
e.err = errors.New("The camera with the address " + e.Address + " was not found by cameradar")
test.expected = removeResult(test.expected, index)
test.expected = Extend(test.expected, e)
fmt.Println("Should have been valid but was not found : ", e.Address)
}
}
+25 -20
View File
@@ -17,6 +17,7 @@ package main
import (
"bytes"
"encoding/xml"
"errors"
"fmt"
"io"
"io/ioutil"
@@ -60,9 +61,6 @@ type JUnitFailure struct {
// WriteResults will output the results in the standard output as well as concatenate them in an XML JUnit report
func (t *Tester) WriteResults(result Test, output string) bool {
fmt.Printf("Displaying results...\n")
t.writeConsoleReport(result)
file, err := os.OpenFile(output, os.O_RDONLY|os.O_CREATE, 0644)
if err != nil {
fmt.Printf("Error opening XML: %s\n", err)
@@ -72,7 +70,7 @@ func (t *Tester) WriteResults(result Test, output string) bool {
err = t.writeJUnitReportXML(result, file, output)
if err != nil {
fmt.Printf("Error writing XML: %s\n", err)
fmt.Printf("The tests were unsuccessful: %s\n", err)
return false
}
fmt.Printf("-> JUnit XML report written: %s\n", output)
@@ -93,7 +91,7 @@ func (t *Tester) writeJUnitReportXML(result Test, rw io.ReadWriter, output strin
ts := JUnitTestSuite{
Tests: len(result.result) + len(result.expected),
Failures: 0,
Failures: len(result.expected),
Time: fmt.Sprintf("%.6f", result.time.Seconds()),
TestCases: []JUnitTestCase{},
}
@@ -103,7 +101,7 @@ func (t *Tester) writeJUnitReportXML(result Test, rw io.ReadWriter, output strin
Time: fmt.Sprintf("%.6f", result.time.Seconds()),
Failure: nil,
}
testCase.Message = "The stream " + r.Address + " could be accessed and its thumbnail was properly generated"
testCase.Message = "The stream " + r.Address + " had the expected result"
ts.TestCases = append(ts.TestCases, testCase)
}
@@ -118,6 +116,24 @@ func (t *Tester) writeJUnitReportXML(result Test, rw io.ReadWriter, output strin
Type: "",
}
}
ts.TestCases = append(ts.TestCases, testCase)
}
successCount := 0
failureCount := 0
for _, test := range ts.TestCases {
if test.Failure != nil {
failureCount++
} else {
successCount++
}
}
fmt.Println("--- Test summary ---")
if successCount > 0 {
fmt.Printf("Results: %d/%d (%d%%)\n", successCount, successCount+failureCount, successCount*100/(successCount+failureCount))
fmt.Printf("Time: %.6fs\n", result.time.Seconds())
} else {
fmt.Printf("No test in success\n")
}
suites.TestSuites = append(suites.TestSuites, ts)
@@ -134,19 +150,8 @@ func (t *Tester) writeJUnitReportXML(result Test, rw io.ReadWriter, output strin
}
writer := io.Writer(w)
writer.Write(bytes)
if failureCount > 0 {
return errors.New("Some cameras were not successfully accessed.")
}
return nil
}
func (t *Tester) writeConsoleReport(result Test) bool {
successCount := len(result.result)
failureCount := len(result.expected)
fmt.Println("--- Test summary ---")
if successCount > 0 {
fmt.Printf("Results: %d/%d (%d%%)\n", successCount, successCount+failureCount, successCount*100/(successCount+failureCount))
fmt.Printf("Time: %.6fs\n", result.time.Seconds())
} else {
fmt.Printf("No test in success\n")
}
return true
}
+6 -2
View File
@@ -32,9 +32,11 @@ function make_docker_command {
function start_test {
./docker/gen_cameras.sh start $1 ./docker/cameratest.conf.tmpl.json
eval $cmd
make_docker_command $1
eval $cmd
ret=$?
./docker/gen_cameras.sh stop
return $ret
}
# build images
@@ -50,9 +52,11 @@ echo "starting mysql"
docker pull mysql:5.7
docker run --name cameradar-database -e MYSQL_DATABASE=cmrdr -e MYSQL_ROOT_PASSWORD=root -d mysql:5.7
start_test 1
start_test 5
ret=$?
echo "Tests returned ${ret}"
# stop mysql
echo "stopping mysql"
docker rm -f cameradar-database
exit $ret