IOS-103 merge in sync IOSAD-103
authorDirk Zimmermann <dz@pep.security>
Sat, 01 Dec 2018 15:21:50 +0100
branchIOSAD-103
changeset 31680cf9b5e8afeb
parent 3158 6ff3fe9912ec
parent 3167 e7a7a92570b0
child 3172 8178a8ad33b2
IOS-103 merge in sync
test/src/engine_tests/SyncTests.cc
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/clean_sync_leftovers.sh	Sat Dec 01 15:21:50 2018 +0100
     1.3 @@ -0,0 +1,6 @@
     1.4 +#!/bin/bash
     1.5 +
     1.6 +cd src; hg status . | sed '/?\ /!d' | sed 's/?\ //' | xargs rm
     1.7 +cd ../asn.1; hg status . | sed '/?\ /!d' | sed 's/?\ //' |  xargs rm
     1.8 +cd ../sync; hg status . | sed '/?\ /!d' | sed 's/?\ //' |  xargs rm
     1.9 +cd ..
     2.1 --- a/sync/gen_statemachine.ysl2	Mon Nov 26 06:02:15 2018 +0100
     2.2 +++ b/sync/gen_statemachine.ysl2	Sat Dec 01 15:21:50 2018 +0100
     2.3 @@ -701,7 +701,7 @@
     2.4              event = Init;
     2.5          }
     2.6          else if (next_state < None) {
     2.7 -            return PEP_STATEMACHINE_ERROR - state;
     2.8 +            return PEP_STATEMACHINE_ERROR - next_state;
     2.9          }
    2.10          break;
    2.11      }
     3.1 --- a/test/Makefile	Mon Nov 26 06:02:15 2018 +0100
     3.2 +++ b/test/Makefile	Sat Dec 01 15:21:50 2018 +0100
     3.3 @@ -34,6 +34,9 @@
     3.4  
     3.5  ifeq ($(OPENPGP),NETPGP)
     3.6  	LDLIBS+= -lnetpgp
     3.7 +ifeq ($(BUILD_FOR),Linux)
     3.8 +	LDLIBS+= -ltre
     3.9 +endif
    3.10  endif
    3.11  
    3.12  ifdef SQLITE3_FROM_OS
     4.1 --- a/test/include/EngineTestSuite.h	Mon Nov 26 06:02:15 2018 +0100
     4.2 +++ b/test/include/EngineTestSuite.h	Sat Dec 01 15:21:50 2018 +0100
     4.3 @@ -23,7 +23,7 @@
     4.4          PEP_SESSION session;
     4.5          string test_home;
     4.6          string real_home;
     4.7 -        string prev_gpg_home;
     4.8 +        string prev_pgp_home;
     4.9          string name;
    4.10          
    4.11          string current_test_name;
     5.1 --- a/test/include/pEpTestOutput.h	Mon Nov 26 06:02:15 2018 +0100
     5.2 +++ b/test/include/pEpTestOutput.h	Sat Dec 01 15:21:50 2018 +0100
     5.3 @@ -5,6 +5,7 @@
     5.4  #include <cpptest.h>
     5.5  #include <vector>
     5.6  #include <string>
     5.7 +#include <utility>
     5.8  
     5.9  namespace Test {
    5.10      class pEpTestOutput : public Output {
    5.11 @@ -37,7 +38,7 @@
    5.12              std::string _suite_name;
    5.13              std::string _test_name;
    5.14              std::vector<Source> _test_errors;
    5.15 -            
    5.16 +            std::vector<std::pair<std::string,Source>> _all_errors;            
    5.17      };
    5.18  }
    5.19  #endif
    5.20 \ No newline at end of file
     6.1 --- a/test/src/EngineTestSuite.cc	Mon Nov 26 06:02:15 2018 +0100
     6.2 +++ b/test/src/EngineTestSuite.cc	Sat Dec 01 15:21:50 2018 +0100
     6.3 @@ -98,10 +98,12 @@
     6.4      
     6.5      set_my_name();
     6.6  
     6.7 +#ifndef USE_NETPGP
     6.8      success = system("gpgconf --kill all");
     6.9      if (success != 0)
    6.10          throw std::runtime_error("SETUP: Error when executing 'gpgconf --kill all'.");
    6.11   //   sleep(1); // hopefully enough time for the system to recognise that it is dead. *sigh*    
    6.12 +#endif
    6.13  
    6.14      if (stat(test_home.c_str(), &dirchk) == 0) {
    6.15          if (!S_ISDIR(dirchk.st_mode))
    6.16 @@ -110,7 +112,6 @@
    6.17          struct stat buf;
    6.18  
    6.19          if (stat(test_home.c_str(), &buf) == 0) {
    6.20 -//            cout << test_home << " exists. We'll recursively delete. We hope we're not horking your whole system..." << endl;
    6.21              int success = nftw((test_home + "/.").c_str(), util_delete_filepath, 100, FTW_DEPTH);
    6.22          }
    6.23      }
    6.24 @@ -133,36 +134,43 @@
    6.25      if (errchk != 0)
    6.26          throw std::runtime_error("Error creating a test directory.");
    6.27  
    6.28 +
    6.29      // TODO: This is *nix specific, which the current testing env is anyway,
    6.30      // but it needn't remain so forever and always
    6.31 -    char* tmp = getenv("GNUPGHOME");
    6.32 +
    6.33 +    string home = getenv("HOME");
    6.34 +
    6.35 +    char* tmp = NULL;
    6.36 +    
    6.37 +    tmp = getenv("GNUPGHOME");
    6.38 +
    6.39 +    prev_pgp_home.clear();
    6.40 +    
    6.41      if (tmp)
    6.42 -        prev_gpg_home = tmp;
    6.43 +        prev_pgp_home = tmp;
    6.44          
    6.45      if (temp_test_home.empty())
    6.46          throw std::runtime_error("SETUP: BAD INITIALISATION. No test home.");
    6.47 -
    6.48      
    6.49 -    string home = getenv("HOME");
    6.50      assert(temp_test_home.compare(home) != 0);
    6.51      assert(temp_test_home.compare(home + "/") != 0);
    6.52      assert(temp_test_home.compare(home + "/.gnupg") != 0); // This is an EXCLUSION test, so we leave this.
    6.53      assert(temp_test_home.compare(home + ".gnupg") != 0);
    6.54      assert(temp_test_home.compare(home + "/gnupg") != 0);
    6.55      assert(temp_test_home.compare(home + "gnupg") != 0);
    6.56 -    assert(temp_test_home.compare(prev_gpg_home) != 0);
    6.57 -    assert(temp_test_home.compare(prev_gpg_home + "/gnupg") != 0);
    6.58 -    assert(temp_test_home.compare(prev_gpg_home + "gnupg") != 0);
    6.59 -    assert(temp_test_home.compare(prev_gpg_home + "/.gnupg") != 0);
    6.60 -    assert(temp_test_home.compare(prev_gpg_home + ".gnupg") != 0);
    6.61 +    assert(temp_test_home.compare(prev_pgp_home) != 0);
    6.62 +    assert(temp_test_home.compare(prev_pgp_home + "/gnupg") != 0);
    6.63 +    assert(temp_test_home.compare(prev_pgp_home + "gnupg") != 0);
    6.64 +    assert(temp_test_home.compare(prev_pgp_home + "/.gnupg") != 0);
    6.65 +    assert(temp_test_home.compare(prev_pgp_home + ".gnupg") != 0);
    6.66  
    6.67      if (temp_test_home.compare(home) == 0 || temp_test_home.compare(home + "/") == 0 ||
    6.68          temp_test_home.compare(home + "/gnupg") == 0 || temp_test_home.compare(home + "gnupg") == 0 ||
    6.69          temp_test_home.compare(home + "/.gnupg") == 0 || temp_test_home.compare(home + ".gnupg") == 0 ||
    6.70 -        temp_test_home.compare(prev_gpg_home) == 0 || temp_test_home.compare(prev_gpg_home + "/gnupg") == 0 ||
    6.71 -        temp_test_home.compare(prev_gpg_home + "gnupg") == 0 || temp_test_home.compare(prev_gpg_home + "/.gnupg") == 0 ||
    6.72 -        temp_test_home.compare(prev_gpg_home + ".gnupg") == 0)
    6.73 -        throw std::runtime_error("SETUP: new GNUPGHOME threatens to mess up user GNUPGHOME (and delete all their keys). NO DICE.");
    6.74 +        temp_test_home.compare(prev_pgp_home) == 0 || temp_test_home.compare(prev_pgp_home + "/gnupg") == 0 ||
    6.75 +        temp_test_home.compare(prev_pgp_home + "gnupg") == 0 || temp_test_home.compare(prev_pgp_home + "/.gnupg") == 0 ||
    6.76 +        temp_test_home.compare(prev_pgp_home + ".gnupg") == 0)
    6.77 +        throw std::runtime_error("SETUP: new pgp homedir threatens to mess up user pgp homedir (and delete all their keys). NO DICE.");
    6.78      
    6.79  //    cout << "Ok - checked if new test home will be safe. We'll try and make the directory, deleting it if it has already exists." << endl;
    6.80      cout << "Test home directory is " << temp_test_home << endl;
    6.81 @@ -207,11 +215,15 @@
    6.82      release(session);
    6.83      session = NULL;
    6.84          
    6.85 -    int success = system("gpgconf --kill all");
    6.86 +    int success = 0;    
    6.87 +
    6.88 +#ifndef USE_NETPGP        
    6.89 +    success = system("gpgconf --kill all");
    6.90      if (success != 0)
    6.91          throw std::runtime_error("RESTORE: Error when executing 'gpgconf --kill all'.");
    6.92 +#endif
    6.93  
    6.94 -    success = setenv("GNUPGHOME", prev_gpg_home.c_str(), 1);
    6.95 +    success = setenv("GNUPGHOME", prev_pgp_home.c_str(), 1);
    6.96      if (success != 0)
    6.97          throw std::runtime_error("RESTORE: Warning - cannot restore GNUPGHOME. Either set environment variable manually back to your home, or quit this session!");
    6.98                  
     7.1 --- a/test/src/SuiteMaker.cc	Mon Nov 26 06:02:15 2018 +0100
     7.2 +++ b/test/src/SuiteMaker.cc	Sat Dec 01 15:21:50 2018 +0100
     7.3 @@ -53,6 +53,7 @@
     7.4  #include "CrashdumpTests.h"
     7.5  #include "CaseAndDotAddressTests.h"
     7.6  #include "ExpiredSubkeyTests.h"
     7.7 +#include "LeastCommonDenomColorTests.h"
     7.8  #include "ExternalRevokeTests.h"
     7.9  #include "UserIDAliasTests.h"
    7.10  
    7.11 @@ -99,12 +100,13 @@
    7.12      "CrashdumpTests",
    7.13      "CaseAndDotAddressTests",
    7.14      "ExpiredSubkeyTests",
    7.15 +    "LeastCommonDenomColorTests",
    7.16      "ExternalRevokeTests",
    7.17      "UserIDAliasTests",
    7.18  };
    7.19  
    7.20  // This file is generated, so magic constants are ok.
    7.21 -int SuiteMaker::num_suites = 43;
    7.22 +int SuiteMaker::num_suites = 44;
    7.23  
    7.24  void SuiteMaker::suitemaker_build(const char* test_class_name, const char* test_home, Test::Suite** test_suite) {
    7.25      if (strcmp(test_class_name, "DecorateTests") == 0)
    7.26 @@ -189,6 +191,8 @@
    7.27          *test_suite = new CaseAndDotAddressTests(test_class_name, test_home);
    7.28      else if (strcmp(test_class_name, "ExpiredSubkeyTests") == 0)
    7.29          *test_suite = new ExpiredSubkeyTests(test_class_name, test_home);
    7.30 +    else if (strcmp(test_class_name, "LeastCommonDenomColorTests") == 0)
    7.31 +        *test_suite = new LeastCommonDenomColorTests(test_class_name, test_home);
    7.32      else if (strcmp(test_class_name, "ExternalRevokeTests") == 0)
    7.33          *test_suite = new ExternalRevokeTests(test_class_name, test_home);
    7.34      else if (strcmp(test_class_name, "UserIDAliasTests") == 0)
     8.1 --- a/test/src/engine_tests/MessageTwoPointOhTests.cc	Mon Nov 26 06:02:15 2018 +0100
     8.2 +++ b/test/src/engine_tests/MessageTwoPointOhTests.cc	Sat Dec 01 15:21:50 2018 +0100
     8.3 @@ -28,7 +28,7 @@
     8.4  
     8.5  void MessageTwoPointOhTests::check_message_two_point_oh() {
     8.6  
     8.7 -    PEP_comm_type carol_comm_type = PEP_ct_OpenPGP_unconfirmed;
     8.8 +    PEP_comm_type carol_comm_type = PEP_ct_pEp;
     8.9  
    8.10      // message_api test code
    8.11  
     9.1 --- a/test/src/engine_tests/ReencryptPlusExtraKeysTests.cc	Mon Nov 26 06:02:15 2018 +0100
     9.2 +++ b/test/src/engine_tests/ReencryptPlusExtraKeysTests.cc	Sat Dec 01 15:21:50 2018 +0100
     9.3 @@ -109,11 +109,10 @@
     9.4      cout << decrypted_text << endl;
     9.5  
     9.6      cout << "Status is " << tl_status_string(status) << endl;
     9.7 -    TEST_ASSERT_MSG(decrypted_text, "No decrypted test");
     9.8 -    TEST_ASSERT_MSG(rating, "No rating. FIXME: what???");
     9.9 +    TEST_ASSERT_MSG(decrypted_text != NULL, "No decrypted test");
    9.10      TEST_ASSERT_MSG((flags & PEP_decrypt_flag_src_modified) == 0, "Source was modified, but shouldn't have been.");
    9.11      
    9.12 -    TEST_ASSERT_MSG(!modified_src, "Modified source was returned, but should not have been generated");
    9.13 +    TEST_ASSERT_MSG(modified_src == NULL, "Modified source was returned, but should not have been generated");
    9.14      //cout << modified_src << endl;
    9.15      
    9.16      free(decrypted_text);
    9.17 @@ -143,9 +142,9 @@
    9.18      cout << "Status is " << tl_status_string(status) << endl;
    9.19  
    9.20  
    9.21 -    TEST_ASSERT_MSG(decrypted_text, "No decrypted text");
    9.22 -    TEST_ASSERT_MSG(rating, "No rating. FIXME: what???");
    9.23 -
    9.24 +    TEST_ASSERT_MSG(decrypted_text != NULL, "No decrypted text");
    9.25 +    TEST_ASSERT_MSG(modified_src != NULL, "No reeencrypted text!");
    9.26 +    
    9.27      free(decrypted_text);
    9.28      decrypted_text = nullptr;
    9.29  
    9.30 @@ -224,18 +223,12 @@
    9.31                                    &flags,
    9.32                                    &modified_src);
    9.33  
    9.34 -    cout << decrypted_text << endl;
    9.35 +    cout << (decrypted_text ? decrypted_text : "No decrypted text") << endl;
    9.36      cout << "Status is " << tl_status_string(status) << endl;
    9.37  
    9.38 -    cout << "1";
    9.39 -    TEST_ASSERT_MSG(decrypted_text, "No decrypted test");
    9.40 -    cout << "2";
    9.41 -    TEST_ASSERT_MSG(rating, "No rating. FIXME: what???");
    9.42 -    cout << "3";
    9.43 +    TEST_ASSERT_MSG(decrypted_text != NULL, "No decrypted test");
    9.44      TEST_ASSERT_MSG((flags & PEP_decrypt_flag_src_modified) == 0, "Source was modified, but shouldn't have been.");
    9.45 -    cout << "4";    
    9.46 -    TEST_ASSERT_MSG(!modified_src, "Modified source was returned, but should not have been generated");
    9.47 -    cout << "5";
    9.48 +    TEST_ASSERT_MSG(modified_src == NULL, "Modified source was returned, but should not have been generated");
    9.49  
    9.50      free(decrypted_text);
    9.51      decrypted_text = nullptr;
    9.52 @@ -263,8 +256,8 @@
    9.53      cout << decrypted_text << endl;
    9.54      cout << "Status is " << tl_status_string(status) << endl;
    9.55  
    9.56 -    TEST_ASSERT_MSG(decrypted_text, "No decrypted test");
    9.57 -    TEST_ASSERT_MSG(rating, "No rating. FIXME: what???");
    9.58 +    TEST_ASSERT_MSG(decrypted_text != NULL, "No decrypted test");
    9.59 +    TEST_ASSERT_MSG(modified_src != NULL, "No reeencrypted text!");
    9.60  
    9.61      free(decrypted_text);
    9.62      decrypted_text = nullptr;
    9.63 @@ -350,10 +343,9 @@
    9.64      cout << decrypted_text << endl;
    9.65      cout << "Status is " << tl_status_string(status) << endl;
    9.66  
    9.67 -    TEST_ASSERT_MSG(decrypted_text, "No decrypted test");
    9.68 -    TEST_ASSERT_MSG(rating, "No rating. FIXME: what???");
    9.69 +    TEST_ASSERT_MSG(decrypted_text != NULL, "No decrypted test");
    9.70      TEST_ASSERT_MSG((flags & PEP_decrypt_flag_src_modified) == 0, "Source was modified, but shouldn't have been.");    
    9.71 -    TEST_ASSERT_MSG(!modified_src, "Modified source was returned, but should not have been generated");
    9.72 +    TEST_ASSERT_MSG(modified_src == NULL, "Modified source was returned, but should not have been generated");
    9.73  
    9.74      free(decrypted_text);
    9.75      decrypted_text = nullptr;
    9.76 @@ -381,8 +373,7 @@
    9.77      cout << decrypted_text << endl;
    9.78      cout << "Status is " << tl_status_string(status) << endl;
    9.79  
    9.80 -    TEST_ASSERT_MSG(decrypted_text, "No decrypted test");
    9.81 -    TEST_ASSERT_MSG(rating, "No rating. FIXME: what???");
    9.82 +    TEST_ASSERT_MSG(decrypted_text != NULL, "No decrypted test");
    9.83  
    9.84      free(decrypted_text);
    9.85      decrypted_text = nullptr;
    10.1 --- a/test/src/engine_tests/SyncTests.cc	Mon Nov 26 06:02:15 2018 +0100
    10.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.3 @@ -1,179 +0,0 @@
    10.4 -// This file is under GNU General Public License 3.0
    10.5 -// see LICENSE.txt
    10.6 -
    10.7 -#include <stdlib.h>
    10.8 -#include <string>
    10.9 -
   10.10 -#include "pEpEngine.h"
   10.11 -
   10.12 -#include "pEp_internal.h"
   10.13 -#include "KeySync_fsm.h"
   10.14 -#include "sync_codec.h"
   10.15 -
   10.16 -#include "EngineTestSessionSuite.h"
   10.17 -#include "SyncTests.h"
   10.18 -
   10.19 -using namespace std;
   10.20 -
   10.21 -void Sync_Adapter::processing()
   10.22 -{
   10.23 -    cout << "waiting for processing\n";
   10.24 -    while (!q.empty()) {
   10.25 -        nanosleep((const struct timespec[]){{0, 100000000L}}, NULL);
   10.26 -    }
   10.27 -}
   10.28 -
   10.29 -PEP_STATUS Sync_Adapter::notifyHandshake(
   10.30 -        pEp_identity *me,
   10.31 -        pEp_identity *partner,
   10.32 -        sync_handshake_signal signal
   10.33 -    )
   10.34 -{
   10.35 -    return PEP_STATUS_OK;
   10.36 -}
   10.37 -
   10.38 -int Sync_Adapter::inject_sync_event(SYNC_EVENT ev, void *management)
   10.39 -{
   10.40 -    Sync_event_t *_ev = ev;
   10.41 -    switch (_ev->fsm) {
   10.42 -        case Sync_PR_keysync:
   10.43 -            cout << "injecting event " << KeySync_event_name(_ev->event) << "\n";
   10.44 -            break;
   10.45 -        default:
   10.46 -            cout << "unknown state machine: " << _ev->fsm << "\n";
   10.47 -            assert(0);
   10.48 -    }
   10.49 -    auto adapter = static_cast< Sync_Adapter *>(management);
   10.50 -    adapter->q.push_front(ev);
   10.51 -    return 0;
   10.52 -}
   10.53 -
   10.54 -Sync_event_t *Sync_Adapter::retrieve_next_sync_event(void *management, time_t threshold)
   10.55 -{
   10.56 -    auto adapter = static_cast< Sync_Adapter *>(management);
   10.57 -    time_t started = time(nullptr);
   10.58 -    bool timeout = false;
   10.59 -
   10.60 -    while (adapter->q.empty()) {
   10.61 -        int i = 0;
   10.62 -        ++i;
   10.63 -        if (i > 10) {
   10.64 -            if (time(nullptr) > started + threshold) {
   10.65 -                timeout = true;
   10.66 -                break;
   10.67 -            }
   10.68 -            i = 0;
   10.69 -        }
   10.70 -        nanosleep((const struct timespec[]){{0, 100000000L}}, NULL);
   10.71 -    }
   10.72 -
   10.73 -    if (timeout)
   10.74 -        return SYNC_TIMEOUT_EVENT;
   10.75 -
   10.76 -    Sync_event_t *ev = adapter->q.pop_front();
   10.77 -    if (ev) {
   10.78 -        switch (ev->fsm) {
   10.79 -            case Sync_PR_keysync:
   10.80 -                cout << "sync thread: retrieving event " << KeySync_event_name(ev->event) << "\n";
   10.81 -                break;
   10.82 -            default:
   10.83 -                cout << "sync thread: unknown state machine: " << ev->fsm << "\n";
   10.84 -                assert(0);
   10.85 -        }
   10.86 -    }
   10.87 -    else {
   10.88 -        cout << "sync thread: retrieving shutdown\n";
   10.89 -    }
   10.90 -
   10.91 -    return ev;
   10.92 -}
   10.93 -
   10.94 -PEP_STATUS Sync_Adapter::messageToSend(struct _message *msg)
   10.95 -{
   10.96 -    assert(msg && msg->attachments);
   10.97 -    
   10.98 -    cout << "sending message:\n";
   10.99 -
  10.100 -    for (bloblist_t *b = msg->attachments; b && b->value; b = b->next) {
  10.101 -        if (b->mime_type && strcasecmp(b->mime_type, "application/pEp.sync") == 0) {
  10.102 -            assert(msg->from && msg->from->address && msg->from->username);
  10.103 -            cout << "<!-- " << msg->from->username << " <" << msg->from->address << "> -->\n";
  10.104 -            char *text = NULL;
  10.105 -            PEP_STATUS status = PER_to_XER_Sync_msg(msg->attachments->value, msg->attachments->size, &text);
  10.106 -            assert(status == PEP_STATUS_OK);
  10.107 -            cout << text << "\n";
  10.108 -            free(text);
  10.109 -        }
  10.110 -    }
  10.111 -
  10.112 -    free_message(msg);
  10.113 -    return PEP_STATUS_OK;
  10.114 -}
  10.115 -
  10.116 -void Sync_Adapter::sync_thread(PEP_SESSION session, Sync_Adapter *adapter)
  10.117 -{
  10.118 -    cout << "sync_thread: startup\n";
  10.119 -    do_sync_protocol(session, adapter);
  10.120 -    cout << "sync_thread: shutdown\n";
  10.121 -}
  10.122 -
  10.123 -SyncTests::SyncTests(string suitename, string test_home_dir) :
  10.124 -    EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {
  10.125 -    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("SyncTests::check_sync"),
  10.126 -                                                                      static_cast<Func>(&SyncTests::check_sync)));
  10.127 -}
  10.128 -
  10.129 -void SyncTests::setup()
  10.130 -{
  10.131 -    EngineTestSessionSuite::setup();
  10.132 -
  10.133 -    pEp_identity *self = new_identity("alice@synctests.pEp", nullptr, "23", "Alice Miller");
  10.134 -    assert(self);
  10.135 -    cout << "setting own identity for " << self->address << "\n";
  10.136 -    PEP_STATUS status = myself(session, self);
  10.137 -    assert(self->me);
  10.138 -    assert(self->fpr);
  10.139 -    cout << "fpr: " << self->fpr << "\n";
  10.140 -    free_identity(self);
  10.141 -
  10.142 -    status = init(&sync, Sync_Adapter::messageToSend, Sync_Adapter::inject_sync_event);
  10.143 -    TEST_ASSERT(status == PEP_STATUS_OK);
  10.144 -
  10.145 -    cout << "initialize sync and start first state machine\n";
  10.146 -    status = register_sync_callbacks(
  10.147 -            sync,
  10.148 -            (void *) &adapter.q,
  10.149 -            Sync_Adapter::notifyHandshake,
  10.150 -            Sync_Adapter::retrieve_next_sync_event
  10.151 -        );
  10.152 -    TEST_ASSERT(status == PEP_STATUS_OK);
  10.153 -    TEST_ASSERT(sync->sync_state.keysync.state == Sole);
  10.154 -
  10.155 -    cout << "creating thread for sync\n";
  10.156 -    sync_thread = new thread(Sync_Adapter::sync_thread, sync, &adapter);
  10.157 -}
  10.158 -
  10.159 -void SyncTests::tear_down()
  10.160 -{
  10.161 -    adapter.processing();
  10.162 -
  10.163 -    cout << "sending shutdown to sync thread\n";
  10.164 -    adapter.q.push_front(nullptr);
  10.165 -    sync_thread->join();
  10.166 -
  10.167 -    unregister_sync_callbacks(sync);
  10.168 -    release(sync);
  10.169 -
  10.170 -    EngineTestSessionSuite::tear_down();
  10.171 -}
  10.172 -
  10.173 -void SyncTests::check_sync()
  10.174 -{
  10.175 -    cout << "check_sync(): trigger KeyGen event\n";
  10.176 -    signal_Sync_event(sync, Sync_PR_keysync, KeyGen);
  10.177 -    adapter.processing();
  10.178 -
  10.179 -    cout << "check_sync(): cry for unknown key\n";
  10.180 -    signal_Sync_event(sync, Sync_PR_keysync, CannotDecrypt);
  10.181 -}
  10.182 -
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/test/src/engine_tests/SyncTests.cc.b0rken	Sat Dec 01 15:21:50 2018 +0100
    11.3 @@ -0,0 +1,179 @@
    11.4 +// This file is under GNU General Public License 3.0
    11.5 +// see LICENSE.txt
    11.6 +
    11.7 +#include <stdlib.h>
    11.8 +#include <string>
    11.9 +
   11.10 +#include "pEpEngine.h"
   11.11 +
   11.12 +#include "pEp_internal.h"
   11.13 +#include "KeySync_fsm.h"
   11.14 +#include "sync_codec.h"
   11.15 +
   11.16 +#include "EngineTestSessionSuite.h"
   11.17 +#include "SyncTests.h"
   11.18 +
   11.19 +using namespace std;
   11.20 +
   11.21 +void Sync_Adapter::processing()
   11.22 +{
   11.23 +    cout << "waiting for processing\n";
   11.24 +    while (!q.empty()) {
   11.25 +        nanosleep((const struct timespec[]){{0, 100000000L}}, NULL);
   11.26 +    }
   11.27 +}
   11.28 +
   11.29 +PEP_STATUS Sync_Adapter::notifyHandshake(
   11.30 +        pEp_identity *me,
   11.31 +        pEp_identity *partner,
   11.32 +        sync_handshake_signal signal
   11.33 +    )
   11.34 +{
   11.35 +    return PEP_STATUS_OK;
   11.36 +}
   11.37 +
   11.38 +int Sync_Adapter::inject_sync_event(SYNC_EVENT ev, void *management)
   11.39 +{
   11.40 +    Sync_event_t *_ev = ev;
   11.41 +    switch (_ev->fsm) {
   11.42 +        case Sync_PR_keysync:
   11.43 +            cout << "injecting event " << KeySync_event_name(_ev->event) << "\n";
   11.44 +            break;
   11.45 +        default:
   11.46 +            cout << "unknown state machine: " << _ev->fsm << "\n";
   11.47 +            assert(0);
   11.48 +    }
   11.49 +    auto adapter = static_cast< Sync_Adapter *>(management);
   11.50 +    adapter->q.push_front(ev);
   11.51 +    return 0;
   11.52 +}
   11.53 +
   11.54 +Sync_event_t *Sync_Adapter::retrieve_next_sync_event(void *management, time_t threshold)
   11.55 +{
   11.56 +    auto adapter = static_cast< Sync_Adapter *>(management);
   11.57 +    time_t started = time(nullptr);
   11.58 +    bool timeout = false;
   11.59 +
   11.60 +    while (adapter->q.empty()) {
   11.61 +        int i = 0;
   11.62 +        ++i;
   11.63 +        if (i > 10) {
   11.64 +            if (time(nullptr) > started + threshold) {
   11.65 +                timeout = true;
   11.66 +                break;
   11.67 +            }
   11.68 +            i = 0;
   11.69 +        }
   11.70 +        nanosleep((const struct timespec[]){{0, 100000000L}}, NULL);
   11.71 +    }
   11.72 +
   11.73 +    if (timeout)
   11.74 +        return SYNC_TIMEOUT_EVENT;
   11.75 +
   11.76 +    Sync_event_t *ev = adapter->q.pop_front();
   11.77 +    if (ev) {
   11.78 +        switch (ev->fsm) {
   11.79 +            case Sync_PR_keysync:
   11.80 +                cout << "sync thread: retrieving event " << KeySync_event_name(ev->event) << "\n";
   11.81 +                break;
   11.82 +            default:
   11.83 +                cout << "sync thread: unknown state machine: " << ev->fsm << "\n";
   11.84 +                assert(0);
   11.85 +        }
   11.86 +    }
   11.87 +    else {
   11.88 +        cout << "sync thread: retrieving shutdown\n";
   11.89 +    }
   11.90 +
   11.91 +    return ev;
   11.92 +}
   11.93 +
   11.94 +PEP_STATUS Sync_Adapter::messageToSend(struct _message *msg)
   11.95 +{
   11.96 +    assert(msg && msg->attachments);
   11.97 +    
   11.98 +    cout << "sending message:\n";
   11.99 +
  11.100 +    for (bloblist_t *b = msg->attachments; b && b->value; b = b->next) {
  11.101 +        if (b->mime_type && strcasecmp(b->mime_type, "application/pEp.sync") == 0) {
  11.102 +            assert(msg->from && msg->from->address && msg->from->username);
  11.103 +            cout << "<!-- " << msg->from->username << " <" << msg->from->address << "> -->\n";
  11.104 +            char *text = NULL;
  11.105 +            PEP_STATUS status = PER_to_XER_Sync_msg(msg->attachments->value, msg->attachments->size, &text);
  11.106 +            assert(status == PEP_STATUS_OK);
  11.107 +            cout << text << "\n";
  11.108 +            free(text);
  11.109 +        }
  11.110 +    }
  11.111 +
  11.112 +    free_message(msg);
  11.113 +    return PEP_STATUS_OK;
  11.114 +}
  11.115 +
  11.116 +void Sync_Adapter::sync_thread(PEP_SESSION session, Sync_Adapter *adapter)
  11.117 +{
  11.118 +    cout << "sync_thread: startup\n";
  11.119 +    do_sync_protocol(session, adapter);
  11.120 +    cout << "sync_thread: shutdown\n";
  11.121 +}
  11.122 +
  11.123 +SyncTests::SyncTests(string suitename, string test_home_dir) :
  11.124 +    EngineTestSessionSuite::EngineTestSessionSuite(suitename, test_home_dir) {
  11.125 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("SyncTests::check_sync"),
  11.126 +                                                                      static_cast<Func>(&SyncTests::check_sync)));
  11.127 +}
  11.128 +
  11.129 +void SyncTests::setup()
  11.130 +{
  11.131 +    EngineTestSessionSuite::setup();
  11.132 +
  11.133 +    pEp_identity *self = new_identity("alice@synctests.pEp", nullptr, "23", "Alice Miller");
  11.134 +    assert(self);
  11.135 +    cout << "setting own identity for " << self->address << "\n";
  11.136 +    PEP_STATUS status = myself(session, self);
  11.137 +    assert(self->me);
  11.138 +    assert(self->fpr);
  11.139 +    cout << "fpr: " << self->fpr << "\n";
  11.140 +    free_identity(self);
  11.141 +
  11.142 +    status = init(&sync, Sync_Adapter::messageToSend, Sync_Adapter::inject_sync_event);
  11.143 +    TEST_ASSERT(status == PEP_STATUS_OK);
  11.144 +
  11.145 +    cout << "initialize sync and start first state machine\n";
  11.146 +    status = register_sync_callbacks(
  11.147 +            sync,
  11.148 +            (void *) &adapter.q,
  11.149 +            Sync_Adapter::notifyHandshake,
  11.150 +            Sync_Adapter::retrieve_next_sync_event
  11.151 +        );
  11.152 +    TEST_ASSERT(status == PEP_STATUS_OK);
  11.153 +    TEST_ASSERT(sync->sync_state.keysync.state == Sole);
  11.154 +
  11.155 +    cout << "creating thread for sync\n";
  11.156 +    sync_thread = new thread(Sync_Adapter::sync_thread, sync, &adapter);
  11.157 +}
  11.158 +
  11.159 +void SyncTests::tear_down()
  11.160 +{
  11.161 +    adapter.processing();
  11.162 +
  11.163 +    cout << "sending shutdown to sync thread\n";
  11.164 +    adapter.q.push_front(nullptr);
  11.165 +    sync_thread->join();
  11.166 +
  11.167 +    unregister_sync_callbacks(sync);
  11.168 +    release(sync);
  11.169 +
  11.170 +    EngineTestSessionSuite::tear_down();
  11.171 +}
  11.172 +
  11.173 +void SyncTests::check_sync()
  11.174 +{
  11.175 +    cout << "check_sync(): trigger KeyGen event\n";
  11.176 +    signal_Sync_event(sync, Sync_PR_keysync, KeyGen);
  11.177 +    adapter.processing();
  11.178 +
  11.179 +    cout << "check_sync(): cry for unknown key\n";
  11.180 +    signal_Sync_event(sync, Sync_PR_keysync, CannotDecrypt);
  11.181 +}
  11.182 +
    12.1 --- a/test/src/pEpTestOutput.cc	Mon Nov 26 06:02:15 2018 +0100
    12.2 +++ b/test/src/pEpTestOutput.cc	Sat Dec 01 15:21:50 2018 +0100
    12.3 @@ -4,6 +4,7 @@
    12.4  #include <vector>
    12.5  #include <string>
    12.6  #include <cstring>
    12.7 +#include <utility>
    12.8  
    12.9  #include "pEpTestOutput.h"
   12.10  using namespace std;
   12.11 @@ -36,6 +37,18 @@
   12.12          int remlen = 56 - finalstr.size();
   12.13          cout << left << setw(finalstr.size()) << finalstr << right << setw(remlen) << "+" << endl;
   12.14          cout << alt_sepline << endl;
   12.15 +        cout << med_sepline;        
   12.16 +        cout << "Error recap:" << endl;
   12.17 +        vector<std::pair<string,Source>>::iterator it;
   12.18 +        for (it = _all_errors.begin(); it != _all_errors.end(); it++) {
   12.19 +            std::pair<string,Source> err = *it;
   12.20 +            cout << lil_sepline;
   12.21 +            cout << left << setw(10) << "Test name: " << err.first << endl;
   12.22 +            Source src = err.second;
   12.23 +            cout << left << setw(25) << "*** Assert location: " << src.file() << ":" << src.line() << endl;
   12.24 +            cout << left << setw(25) << "*** Message: " << src.message() << endl;
   12.25 +        }
   12.26 +        cout << med_sepline << endl << endl;        
   12.27  	}
   12.28  	
   12.29  	void pEpTestOutput::suite_start(int tests, const string& name) {
   12.30 @@ -72,6 +85,7 @@
   12.31      }
   12.32      void pEpTestOutput::test_end(const string& name, bool ok, const Test::Time&) {
   12.33  	    if (!ok) {
   12.34 +            std::pair<string,Source> test_error_set;
   12.35              _suite_failed++;
   12.36              _total_failed++;
   12.37              cout << endl << endl << alt_sepline;
   12.38 @@ -81,7 +95,10 @@
   12.39                  Source src = *it;
   12.40                  cout << lil_sepline;
   12.41                  cout << left << setw(25) << "*** Assert location: " << src.file() << ":" << src.line() << endl;
   12.42 -                cout << left << setw(25) << "*** Message: " << src.message() << endl;                
   12.43 +                cout << left << setw(25) << "*** Message: " << src.message() << endl;
   12.44 +                test_error_set.first = name;
   12.45 +                test_error_set.second = src;
   12.46 +                _all_errors.push_back(test_error_set);                
   12.47              }
   12.48              cout << alt_sepline << endl;
   12.49          }