diff --git a/.travis.yml b/.travis.yml index 8f7b42a..64740ad 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c96fef..3719a74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 : diff --git a/CMakeLists.txt b/CMakeLists.txt index 1c5b70c..178fa71 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/README.md b/README.md index e63665c..3409df3 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/cameradar_standalone/src/describe.cpp b/cameradar_standalone/src/describe.cpp index 4debe44..ae9fb89 100644 --- a/cameradar_standalone/src/describe.cpp +++ b/cameradar_standalone/src/describe.cpp @@ -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; diff --git a/deployment/build_last_package.sh b/deployment/build_last_package.sh index e20428c..12434c2 100755 --- a/deployment/build_last_package.sh +++ b/deployment/build_last_package.sh @@ -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 diff --git a/deployment/cameradar_1.1.2_Release_Linux.tar.gz b/deployment/cameradar_1.1.2_Release_Linux.tar.gz deleted file mode 100644 index 476ae4e..0000000 Binary files a/deployment/cameradar_1.1.2_Release_Linux.tar.gz and /dev/null differ diff --git a/deployment/cameradar_1.1.3_Release_Linux.tar.gz b/deployment/cameradar_1.1.3_Release_Linux.tar.gz new file mode 100644 index 0000000..f4e6acb Binary files /dev/null and b/deployment/cameradar_1.1.3_Release_Linux.tar.gz differ diff --git a/test/build_last_package.sh b/test/build_last_package.sh index 69a1006..07517d6 100755 --- a/test/build_last_package.sh +++ b/test/build_last_package.sh @@ -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 diff --git a/test/camera_emulation_server b/test/camera_emulation_server index b941dd6..fc6d6e1 100755 Binary files a/test/camera_emulation_server and b/test/camera_emulation_server differ diff --git a/test/docker/run_cameradartest.sh b/test/docker/run_cameradartest.sh index 12b7a1f..db3ab4b 100755 --- a/test/docker/run_cameradartest.sh +++ b/test/docker/run_cameradartest.sh @@ -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 diff --git a/test/docker/run_ces.sh b/test/docker/run_ces.sh index 46c0111..9d05b8c 100755 --- a/test/docker/run_ces.sh +++ b/test/docker/run_ces.sh @@ -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}" diff --git a/test/etix_rtsp_server b/test/etix_rtsp_server deleted file mode 100755 index d74a186..0000000 Binary files a/test/etix_rtsp_server and /dev/null differ diff --git a/test/src/db.go b/test/src/db.go index fd91705..5ade4aa 100644 --- a/test/src/db.go +++ b/test/src/db.go @@ -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 } diff --git a/test/src/dropDB.go b/test/src/dropDB.go deleted file mode 100644 index 35f9935..0000000 --- a/test/src/dropDB.go +++ /dev/null @@ -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 -} \ No newline at end of file diff --git a/test/src/getResult.go b/test/src/getResult.go deleted file mode 100644 index 7640691..0000000 --- a/test/src/getResult.go +++ /dev/null @@ -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 -} diff --git a/test/src/main.go b/test/src/main.go index e4e0ec6..1feb0fc 100644 --- a/test/src/main.go +++ b/test/src/main.go @@ -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) } diff --git a/test/src/manager.go b/test/src/manager.go deleted file mode 100644 index 773bd5b..0000000 --- a/test/src/manager.go +++ /dev/null @@ -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 -} diff --git a/test/src/result.go b/test/src/result.go index eaa17d9..bbbbdcd 100644 --- a/test/src/result.go +++ b/test/src/result.go @@ -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 diff --git a/test/src/testCase.go b/test/src/testCase.go index 7fc11e3..bf92567 100644 --- a/test/src/testCase.go +++ b/test/src/testCase.go @@ -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) } } diff --git a/test/src/writeResult.go b/test/src/writeResult.go index a92b551..1b50b74 100644 --- a/test/src/writeResult.go +++ b/test/src/writeResult.go @@ -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 -} diff --git a/test/run.sh b/test/test.sh similarity index 95% rename from test/run.sh rename to test/test.sh index a4f26ed..fd5e952 100755 --- a/test/run.sh +++ b/test/test.sh @@ -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