removed unused variable flag sync
authorKrista 'DarthMama' Bennett <krista@pep.foundation>
Wed, 06 Nov 2019 16:47:13 +0100
branchsync
changeset 4153f4e9a99c1123
parent 4152 d7fcdda581fd
child 4154 f4fa95e8665d
removed unused variable flag
test/Makefile
test/src/ThreadSpamTest.cc
     1.1 --- a/test/Makefile	Tue Oct 29 08:04:06 2019 +0100
     1.2 +++ b/test/Makefile	Wed Nov 06 16:47:13 2019 +0100
     1.3 @@ -55,7 +55,7 @@
     1.4  CXXFLAGS:=-I$(GTEST_INC_DIR) $(filter-out -DNDEBUG,$(CXXFLAGS))
     1.5  
     1.6  # FIXME Possibly missing incdirs: ASN1C_INC
     1.7 -CXXFLAGS+= -I./src -I../sync $(CPPUNIT_INC) $(INC_FLAGS) -Wno-deprecated
     1.8 +CXXFLAGS+= -I./src -I../sync $(CPPUNIT_INC) $(INC_FLAGS) -Wno-deprecated -Wno-unused-variable
     1.9  
    1.10  ifeq ($(OPENPGP),GPG)
    1.11      CXXFLAGS+= -DUSE_GPG $(GPGME_INC)
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/src/ThreadSpamTest.cc	Wed Nov 06 16:47:13 2019 +0100
     2.3 @@ -0,0 +1,145 @@
     2.4 +#include <stdlib.h>
     2.5 +#include <string>
     2.6 +#include <cstring>
     2.7 +#include <thread>
     2.8 +#include <iostream>
     2.9 +#include <mutex>
    2.10 +#include <vector>
    2.11 +
    2.12 +#include "pEpEngine.h"
    2.13 +#include "test_util.h"
    2.14 +#include "TestConstants.h"
    2.15 +#include "Engine.h"
    2.16 +#include "mime.h"
    2.17 +
    2.18 +#include <gtest/gtest.h>
    2.19 +
    2.20 +std::mutex tst_mutex;
    2.21 +
    2.22 +namespace {
    2.23 +
    2.24 +	//The fixture for ThreadSpamTest
    2.25 +    class ThreadSpamTest : public ::testing::Test {
    2.26 +        public:
    2.27 +            Engine* engine;
    2.28 +            PEP_SESSION session;
    2.29 +
    2.30 +        protected:
    2.31 +            // You can remove any or all of the following functions if its body
    2.32 +            // is empty.
    2.33 +            ThreadSpamTest() {
    2.34 +                // You can do set-up work for each test here.
    2.35 +                test_suite_name = ::testing::UnitTest::GetInstance()->current_test_info()->test_suite_name();
    2.36 +                test_name = ::testing::UnitTest::GetInstance()->current_test_info()->name();
    2.37 +                test_path = get_main_test_home_dir() + "/" + test_suite_name + "/" + test_name;
    2.38 +            }
    2.39 +
    2.40 +            ~ThreadSpamTest() override {
    2.41 +                // You can do clean-up work that doesn't throw exceptions here.
    2.42 +            }
    2.43 +
    2.44 +            // If the constructor and destructor are not enough for setting up
    2.45 +            // and cleaning up each test, you can define the following methods:
    2.46 +
    2.47 +            void SetUp() override {
    2.48 +                // Code here will be called immediately after the constructor (right
    2.49 +                // before each test).
    2.50 +
    2.51 +                // Leave this empty if there are no files to copy to the home directory path
    2.52 +                std::vector<std::pair<std::string, std::string>> init_files = std::vector<std::pair<std::string, std::string>>();
    2.53 +
    2.54 +                // Get a new test Engine.
    2.55 +                engine = new Engine(test_path);
    2.56 +                ASSERT_NE(engine, nullptr);
    2.57 +
    2.58 +                // Ok, let's initialize test directories etc.
    2.59 +                engine->prep(NULL, NULL, init_files);
    2.60 +
    2.61 +                // Ok, try to start this bugger.
    2.62 +                engine->start();
    2.63 +                ASSERT_NE(engine->session, nullptr);
    2.64 +                session = engine->session;
    2.65 +
    2.66 +                // Engine is up. Keep on truckin'
    2.67 +            }
    2.68 +
    2.69 +            void TearDown() override {
    2.70 +                // Code here will be called immediately after each test (right
    2.71 +                // before the destructor).
    2.72 +                engine->shut_down();
    2.73 +                delete engine;
    2.74 +                engine = NULL;
    2.75 +                session = NULL;
    2.76 +            }
    2.77 +
    2.78 +        private:
    2.79 +            const char* test_suite_name;
    2.80 +            const char* test_name;
    2.81 +            string test_path;
    2.82 +            // Objects declared here can be used by all tests in the ThreadSpamTest suite.
    2.83 +
    2.84 +    };
    2.85 +
    2.86 +}  // namespace
    2.87 +
    2.88 +void tst_release(PEP_SESSION sess) {
    2.89 +    tst_mutex.lock();
    2.90 +    release(sess);
    2.91 +    tst_mutex.unlock();
    2.92 +}
    2.93 +
    2.94 +void tst_run(int session_number, int num_runs) {
    2.95 +    PEP_SESSION my_sess;
    2.96 +    PEP_STATUS status = init(&my_sess, NULL, NULL);
    2.97 +    if (status != PEP_STATUS_OK) {
    2.98 +        throw string("Could not start session ") + to_string(session_number);
    2.99 +    }
   2.100 +    cout << "Ok, here in the middle of session " << session_number  << endl;
   2.101 +    // Do stuff here
   2.102 +    
   2.103 +    // We're lazy as Hell. We're going to set up one message and try to decrypt it again and again,.
   2.104 +    string msgstr = slurp("test_mails/thread_spam_test.eml");
   2.105 +    
   2.106 +    for (int i = 0; i < num_runs; i++) {
   2.107 +        message* enc_msg = NULL;
   2.108 +        message* dec_msg = NULL;
   2.109 +        stringlist_t* keylist = NULL;
   2.110 +        PEP_rating rating;
   2.111 +        PEP_decrypt_flags_t flags = 0;
   2.112 +        
   2.113 +        status = mime_decode_message(msgstr.c_str(), msgstr.size(), &enc_msg);
   2.114 +        status = decrypt_message(my_sess, enc_msg, &dec_msg, &keylist, &rating, &flags);
   2.115 +        if (status != PEP_STATUS_OK)
   2.116 +            throw string("\aSESSION ") + to_string(session_number) + ": " + tl_status_string(status);
   2.117 +        free_message(enc_msg);
   2.118 +        free_stringlist(keylist);
   2.119 +        free_message(dec_msg);
   2.120 +    }
   2.121 +    
   2.122 +    tst_release(my_sess);
   2.123 +}
   2.124 +
   2.125 +TEST_F(ThreadSpamTest, check_thread_spam) {
   2.126 +    pEp_identity* carol = NULL;
   2.127 +
   2.128 +    PEP_STATUS status = set_up_preset(session, CAROL,
   2.129 +                                      true, true, true, true, true, &carol);
   2.130 +
   2.131 +    ASSERT_EQ(status , PEP_STATUS_OK);
   2.132 +    ASSERT_NE(carol, nullptr);
   2.133 +    
   2.134 +    int NUM_TST_THREADS = 6;
   2.135 +    int NUM_TST_RUNS = 200;
   2.136 +    
   2.137 +    vector<thread> workers;
   2.138 +    
   2.139 +    for (int i = 0; i < NUM_TST_THREADS; i++) {
   2.140 +       workers.push_back(std::thread(tst_run, i, NUM_TST_RUNS));
   2.141 +    }
   2.142 +    auto curr_thread = workers.begin();
   2.143 +    //Do other stuff here.
   2.144 +    while (curr_thread != workers.end()) {
   2.145 +       curr_thread->join();
   2.146 +       curr_thread++;
   2.147 +    }    
   2.148 +}