From 22aea91ecf2314e8e01ce4f817c013f12dfe4499 Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Thu, 7 Nov 2019 13:51:23 +0000 Subject: [PATCH 1/3] + ci pipeline --- .ci/clang-tidy.sh | 32 ++++++++++++++++++++++ .gitlab-ci.yml | 68 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 .ci/clang-tidy.sh create mode 100644 .gitlab-ci.yml diff --git a/.ci/clang-tidy.sh b/.ci/clang-tidy.sh new file mode 100644 index 0000000..eae5b12 --- /dev/null +++ b/.ci/clang-tidy.sh @@ -0,0 +1,32 @@ +#!/bin/sh + +echo "Doing clang-tidy..." +bool=false +# explicitly set IFS to contain only a line feed +IFS=' +' +filelist="$(find . -not \( -path './client/cpptoml/*' -prune \) -type f ! -name "$(printf "*\n*")")" +for file in $filelist; do + if echo "$file" | grep -q -E ".*\.cpp$" ; then + #Extra check missing dependencies due to clang-tidy doesn't toggle exit code. + clang_tidy_lib_check="$(clang-tidy -warnings-as-errors='*' -header-filter='.*,-cpptoml.hpp' -checks='*,-llvm-header-guard,-fuchsia-statically-constructed-objects,-fuchsia-default-arguments,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-pro-bounds-constant-array-index,-bugprone-narrowing-conversions,-cppcoreguidelines-narrowing-conversions,-cppcoreguidelines-pro-type-const-cast,-cppcoreguidelines-pro-type-reinterpret-cast,-hicpp-signed-bitwise,-bugprone-exception-escape,-cppcoreguidelines-pro-type-member-init,-cppcoreguidelines-pro-type-cstyle-cast,-hicpp-member-init' "$file" -- -I. -std=c++14 2>&1)" + for tidy_line in $clang_tidy_lib_check; do + echo "$tidy_line" | grep -q -v -E "^Error while processing*" + if [ $? -eq 1 ]; then + bool=true + fi + echo "$tidy_line" | grep -q -v -E ".* error: .*" + if [ $? -eq 1 ]; then + bool=true + fi + echo "$tidy_line" + done + fi +done +if $bool; then + exit 1 +else + echo "No clang-tidy errors found." +fi + +exit 0 diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..eb1309a --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,68 @@ +--- + +image: samueldebruyn/debian-git:latest + +stages: + - style + - test + - build + + +clang_tidy: + image: jhasse/clang-tidy + stage: style + tags: + - docker-ci + script: + - sh .ci/clang-tidy.sh; + +make_test: + stage: test + tags: + - docker-ci + script: + - apt-get update + - apt-get install -y g++ make cmake clang-tidy + - mkdir current + - ls | grep -v current | xargs mv -t current + - git clone https://github.com/catchorg/Catch2.git + - cd Catch2 + - cmake -Bbuild -H. -DBUILD_TESTING=OFF + - cmake --build build/ --target install + - cd .. + - git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.repo.digitech.hs-emden-leer.de/link/projekte/ws19/vkvm-new/library.git + - mkdir library/build + - cd library/build + - cmake .. + - make + - cd ../../current + - mkdir build + - cd build + - cmake .. + - make + - make test + +cmake_build: + stage: build + tags: + - docker-ci + script: + - apt-get update + - apt-get install -y g++ make cmake clang-tidy + - mkdir current + - ls | grep -v current | xargs mv -t current + - git clone https://github.com/catchorg/Catch2.git + - cd Catch2 + - cmake -Bbuild -H. -DBUILD_TESTING=OFF + - cmake --build build/ --target install + - cd .. + - git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.repo.digitech.hs-emden-leer.de/link/projekte/ws19/vkvm-new/library.git + - mkdir library/build + - cd library/build + - cmake .. + - make + - cd ../../current + - mkdir build + - cd build + - cmake .. + - make \ No newline at end of file From bda7955726ef6141b3721e2d5a3fb56d412314da Mon Sep 17 00:00:00 2001 From: cigerxwinchaker Date: Thu, 7 Nov 2019 17:59:06 +0100 Subject: [PATCH 2/3] aktuelle version. getestet. Es fehlen noch evtl Feature. aber shared memory wird bereit gestellt. Key weitergabe muss noch besprochen werden. --- main/main.cpp | 25 ++++++++++++---- src/SharedMemory.cpp | 70 +++++++++++++++++++++++++++++++++----------- src/SharedMemory.h | 8 +++-- test/test_demo.cpp | 2 +- 4 files changed, 79 insertions(+), 26 deletions(-) diff --git a/main/main.cpp b/main/main.cpp index ff1ca5d..261829f 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -1,19 +1,34 @@ -#include "../src/SharedMemory.h" -#include #include -#include #include +#include "../src/SharedMemory.h" +#include +#include int main(int argc, char** argv) { - sharedMemoryInit(); + initSharedMemory(); struct sigaction sigIntHandler; sigIntHandler.sa_handler = deleteSharedMemory; sigemptyset(&sigIntHandler.sa_mask); sigIntHandler.sa_flags = 0; sigaction(SIGINT, &sigIntHandler, NULL); - sleep(3); // TODO: warte auf eingabe + std::atexit(deleteSharedMemory); + std::string eingabe = ""; + while(eingabe != "exit") { + std::cout << "cmd# "; + std::cin >> eingabe; + //if verschieden information ausgaben + if(eingabe == "info") + { + std::cout << "OUTPUT ------------------------ OUTPUT" << std::endl; + std::cout << "memory ID: " << shmget(impl.sharedMemoryKey, 0, 0) << std::endl; + std::cout << "Max memory Size: " << Max_Memory_Size << std::endl; + std::cout << "OUTPUT ------------------------ OUTPUT" << std::endl; + //Memory that is used now + //outprint of all memory + } + } return 0; } \ No newline at end of file diff --git a/src/SharedMemory.cpp b/src/SharedMemory.cpp index 0e36071..3f7c3cc 100644 --- a/src/SharedMemory.cpp +++ b/src/SharedMemory.cpp @@ -1,44 +1,80 @@ #include -#include -#include #include "SharedMemory.h" #include -#define Max_Memory_Size 8000 -int memoryAccessKey = 12345; -int memID; +key_t changedKey() +{ + int newKey; + std::cout << "Type in a new Key for the Shared Memory Segment" << std::endl; + std::cout << "new Key#"; + std::cin >> newKey; + std::cout <<"New Key is -> " << newKey << std::endl; + return key_t(newKey); +} -void sharedMemoryInit() { - if ((memID = shmget(memoryAccessKey, Max_Memory_Size, IPC_CREAT | IPC_EXCL | 0666)) < 0) { - std::cerr << "Shared memory with Key: " << memoryAccessKey - << " already exists. Delete by Hand before starting vKFM" << std::endl; - exit(0); +std::string getAnswerFromUser() +{ + std::cout <<"answer# "; + std::string answer; + std::cin >> answer; + if(answer.compare("y") == 0 || answer.compare("n") == 0|| answer.compare("override") == 0) { + return answer; } else { - std::cout << "Shared memory with Key: " << memoryAccessKey << " allocated" << std::endl; + std::cout << "wrong input: pls answer with (y) for yes, (n) for no, or (override)\n"; + getAnswerFromUser(); } } +void initSharedMemory(void) { + if(impl.sharedMemoryKey != key_t(0)) { + if (shmget(impl.sharedMemoryKey, Max_Memory_Size, IPC_CREAT | IPC_EXCL | 0666) < 0) + { + std::cout << "Shared Memory with Key: " << impl.sharedMemoryKey << " is already in use\n" + <<"You can change the Key( type -> y or n ), or you can override the shared memory Segment(type -> override)\n"; + std::string answer = getAnswerFromUser(); + if(answer.compare("y") == 0) + { + std::cout << "Please type in a new Key:\n"; + std::cout << "#"; + std::cin >> impl.sharedMemoryKey; + std::cout << "new Try with Key:c " << impl.sharedMemoryKey << std::endl; + initSharedMemory(); + } else if(answer.compare("n") == 0) { + std::cout << "This will end shared memory" < " << impl.sharedMemoryKey << " is not allowed here " << std::endl; + impl.sharedMemoryKey = changedKey(); + initSharedMemory(); + } +} + void deleteSharedMemory(int s) { - if (shmctl(memID, IPC_RMID, NULL) < 0 ) + std::cerr << "programm ended with Code: " << s << std::endl; + if (shmctl(shmget(impl.sharedMemoryKey, 0, 0), IPC_RMID, 0) < 0 ) { - std::cerr << "Failed to remove shared Memory, maybe not existing: try cmd: ipcs " << std::endl; + std::cerr << "Failed to remove shared Memory, maybe not existing: try cmd: ipcs, then delete with ipcrm -m $memID " << std::endl; } else { std::cout << "shared Memory deleted" << std::endl; } - exit(0); } void deleteSharedMemory(void) { - if (shmctl(memID, IPC_RMID, NULL) < 0 ) + if (shmctl(shmget(impl.sharedMemoryKey, 0, 0), IPC_RMID, 0) < 0 ) { std::cerr << "Failed to remove shared Memory, maybe not existing: try cmd: ipcs " << std::endl; } else { std::cout << "shared Memory deleted" << std::endl; } - exit(0); } - diff --git a/src/SharedMemory.h b/src/SharedMemory.h index a4f0406..96aefca 100644 --- a/src/SharedMemory.h +++ b/src/SharedMemory.h @@ -1,13 +1,15 @@ #ifndef SHARED_MEMORY_H #define SHARED_MEMORY_H +#include +#include +#include "internal.h" //ID-Speicherbereich //Größe des Speicherbereichs hier 8MB (8000) #define shmMaxSize 8000 - //Shared-Memory-Segment erstellen oder öffnen – shmget() -void sharedMemoryInit(); +#define Max_Memory_Size 8000 void deleteSharedMemory(int s); void deleteSharedMemory(void); - +void initSharedMemory(void); #endif //SHARED_MEMORY_H diff --git a/test/test_demo.cpp b/test/test_demo.cpp index 4021d86..fde1445 100644 --- a/test/test_demo.cpp +++ b/test/test_demo.cpp @@ -2,6 +2,6 @@ #include "../src/SharedMemory.h" TEST_CASE("Demo test") { - // REQUIRE(test() == 42); + //REQUIRE(test() == 42); } From 121ae391c03e502f4a5243e5bf4fd8ea06799927 Mon Sep 17 00:00:00 2001 From: cigerxwinchaker Date: Thu, 7 Nov 2019 18:05:59 +0100 Subject: [PATCH 3/3] test push der aktuellen quelldateien --- main/main.cpp | 4 ++-- src/SharedMemory.cpp | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/main/main.cpp b/main/main.cpp index 261829f..fdf836c 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -22,10 +22,10 @@ int main(int argc, char** argv) //if verschieden information ausgaben if(eingabe == "info") { - std::cout << "OUTPUT ------------------------ OUTPUT" << std::endl; + std::cout << "OUTPUT ------------------------ OUTPUT\n" << std::endl; std::cout << "memory ID: " << shmget(impl.sharedMemoryKey, 0, 0) << std::endl; std::cout << "Max memory Size: " << Max_Memory_Size << std::endl; - std::cout << "OUTPUT ------------------------ OUTPUT" << std::endl; + std::cout << "OUTPUT ------------------------ OUTPUT\n" << std::endl; //Memory that is used now //outprint of all memory } diff --git a/src/SharedMemory.cpp b/src/SharedMemory.cpp index 3f7c3cc..77520f6 100644 --- a/src/SharedMemory.cpp +++ b/src/SharedMemory.cpp @@ -23,6 +23,7 @@ std::string getAnswerFromUser() std::cout << "wrong input: pls answer with (y) for yes, (n) for no, or (override)\n"; getAnswerFromUser(); } + return "-0"; } @@ -48,7 +49,7 @@ void initSharedMemory(void) { initSharedMemory(); } } else { - std::cout << "Shared Memory ist (Re-) allocated with Key: " << impl.sharedMemoryKey << std::endl; + std::cout << "Shared Memory is (Re-) allocated with Key: " << impl.sharedMemoryKey << std::endl; } } else { std::cerr <<"key -> " << impl.sharedMemoryKey << " is not allowed here " << std::endl;