Не удается запустить пользовательский модульный тест в INet (OmNET++)

РЕДАКТИРОВАТЬ

Оригинальный вопрос усложняет ситуацию, на самом деле проблема намного проще.

Я пытаюсь просто запустить существующие модульные тесты, ничего не добавляя. В папке модульного теста inet/tests/unit я запускаю:

./runtest

и получить это:

andreatino@andreatino-virtual-machine:~/Git/inet/tests/unit$ ./runtest 
opp_test: extracting files from *.test files into work...

Creating Makefile in /home/andreatino/Git/inet/tests/unit/work...
Makefile created, running "make depend" to add dependencies...
Creating dependencies...
intervaltree/test.cc
In file included from /home/andreatino/Downloads/omnetpp-5.0/include/platdep/sockets.h:2:0,
                 from ../../../src/inet/common/precompiled.h:19,
                 from ../../../src/inet/common/INETDefs.h:22,
                 from ../../../src/inet/common/IntervalTree.h:42,
                 from intervaltree/test.cc:4:
/home/andreatino/Downloads/omnetpp-5.0/include/omnetpp/platdep/sockets.h:33:3: error: #error "#include <platdep/sockets.h> must precede <omnetpp.h> (and <platdep/timeutil.h> if present)"
 # error "#include <platdep/sockets.h> must precede <omnetpp.h> (and <platdep/timeutil.h> if present)"
   ^
Makefile:122: recipe for target 'out/gcc-debug//intervaltree/test.o' failed
make: *** [out/gcc-debug//intervaltree/test.o] Error 1

Что происходит?

Внимание Вы можете не читать исходный вопрос. Если только вам не интересно получить дополнительную информацию по этому вопросу.

Оригинальный вопрос

Я пытаюсь запустить пользовательский тест в INet Framework, я добавляю пользовательский тест для компонент, который я пишу. Файлы являются частью этой фиксации.

Я добавляю тест в: inet/tests/unit, см. коммит для файловой структуры.

Тестовые файлы

Тестовый файл:

%description:
Test MacUtils in Ieee80211ac:
- Length of MU bundles is correctly computed.

%includes:
#include "ieee80211ac/MacUtilsTest.h"

%global:

using namespace ::inet::tcp::test::ieee80211ac;

%activity:
MacUtilsTest test = MacUtilsTest();

test.testMaxLengthReturned();

EV << ".\n";

%contains: stdout
l=7
.

И включенный заголовок:

#ifndef __INET_IEEE80211AC_MACUTILSTEST_H
#define __INET_IEEE80211AC_MACUTILSTEST_H

#include "inet/linklayer/ieee80211/mac/IMacParameters.h"
#include "inet/linklayer/ieee80211/mac/IRateSelection.h"
#include "inet/linklayer/ieee80211/mac/AccessCategory.h"
#include "inet/linklayer/ieee80211/mac/IRateControl.h"
#include "inet/linklayer/ieee80211/mac/Ieee80211Frame_m.h"

using namespace inet::ieee80211ac;

namespace inet {

namespace ieee80211ac {
class MacUtils;
class Ieee80211acMUBundleFrame;
}

namespace test {
namespace ieee80211ac {

/**
 * Tests focusing on utils on bundle messages.
 */
class MacUtilsTest
{
    protected:
        class DummyMacParameters : public inet::ieee80211::IMacParameters {
            public:
                virtual const MACAddress& getAddress() const override {}
                virtual bool isEdcaEnabled() const override {return false;}
                virtual simtime_t getSlotTime() const override {return 0;}
                virtual simtime_t getSifsTime() const override {return 0;}
                virtual simtime_t getAifsTime(inet::ieee80211::AccessCategory ac) const override {return 0;}
                virtual simtime_t getEifsTime(inet::ieee80211::AccessCategory ac) const override {return 0;}
                virtual simtime_t getPifsTime() const override {return 0;}
                virtual simtime_t getRifsTime() const override {return 0;}
                virtual int getCwMin(inet::ieee80211::AccessCategory ac) const override {return 0;}
                virtual int getCwMax(inet::ieee80211::AccessCategory ac) const override {return 0;}
                virtual int getCwMulticast(inet::ieee80211::AccessCategory ac) const override {return 0;}
                virtual simtime_t getTxopLimit(inet::ieee80211::AccessCategory ac) const override {return 0;}
                virtual int getShortRetryLimit() const override {return 0;}
                virtual int getLongRetryLimit() const override {return 0;}
                virtual int getRtsThreshold() const override {return 0;}
                virtual simtime_t getPhyRxStartDelay() const override {return 0;}
                virtual bool getUseFullAckTimeout() const override {return false;}
        };

        class DummyRateSelection : public inet::ieee80211::IRateSelection {
            public:
                virtual void setRateControl(inet::ieee80211::IRateControl *rateControl) override {}
                virtual const IIeee80211Mode *getSlowestMandatoryMode() override {return nullptr;}
                virtual const IIeee80211Mode *getModeForUnicastDataOrMgmtFrame(
                        inet::ieee80211::Ieee80211DataOrMgmtFrame *frame) override {return nullptr;}
                virtual const IIeee80211Mode *getModeForMulticastDataOrMgmtFrame(
                        inet::ieee80211::Ieee80211DataOrMgmtFrame *frame) override {return nullptr;}
                virtual const IIeee80211Mode *getModeForControlFrame(
                        inet::ieee80211::Ieee80211Frame *controlFrame) override {return nullptr;}
                virtual const IIeee80211Mode *getResponseControlFrameMode() override {return nullptr;}
        };

    protected:
        DummyMacParameters *macParameters = nullptr;
        DummyRateSelection *rateSelection = nullptr;
        MacUtils *utils = nullptr;
        Ieee80211acMUBundleFrame *bundleFrame = nullptr;

    protected:
        virtual void initialize();

    public:
        MacUtilsTest();
        virtual ~MacUtilsTest();

    public:
        void testMaxLengthReturned();
};

} // namespace ieee80211ac
} // namespace test
} // namespace inet

#endif

И реализация:

#include "MacUtilsTest.h"
#include "inet/linklayer/ieee80211ac/mac/MacUtils.h"
#include "inet/linklayer/ieee80211/mac/MacUtils.h"
#include "inet/linklayer/ieee80211ac/mac/Ieee80211acFrame_m.h"

using namespace inet::ieee80211ac;

namespace inet {
namespace test {
namespace ieee80211ac {

MacUtilsTest::MacUtilsTest()
{
    this->initialize();
}

MacUtilsTest::~MacUtilsTest()
{
    delete this->macParameters;
    delete this->rateSelection;
    delete this->utils;

    for (unsigned int i = 0, l = this->bundleFrame->getSingleFramesArraySize(); i < l; i++)
        delete this->bundleFrame->getSingleFrames(i);
    delete this->bundleFrame;
}

void MacUtilsTest::initialize()
{
    this->macParameters = new MacUtilsTest::DummyMacParameters();
    this->rateSelection = new MacUtilsTest::DummyRateSelection();
    this->utils = new inet::ieee80211ac::MacUtils(this->macParameters, this->rateSelection);

    this->bundleFrame = new Ieee80211acMUBundleFrame("MU Bundle");

    Ieee80211acDataFrame* data1 = new Ieee80211acDataFrame("Data-1");
    data1->setByteLength(3);
    Ieee80211acDataFrame* data2 = new Ieee80211acDataFrame("Data-2");
    data2->setByteLength(6);
    Ieee80211acDataFrame* data3 = new Ieee80211acDataFrame("Data-3");
    data3->setByteLength(7);

    this->bundleFrame->setSingleFramesArraySize(3);
    this->bundleFrame->setSingleFrames(0, *data1);
    this->bundleFrame->setSingleFrames(0, *data2);
    this->bundleFrame->setSingleFrames(0, *data3);
}

void MacUtilsTest::testMaxLengthReturned()
{
    int64_t length = this->utils->getMUBundleByteLength(this->bundleFrame);
    EV << "l=" << length << endl;
}

} // namespace ieee80211ac
} // namespace test
} // namespace inet

Я добавляю их сюда только ради этого вопроса, но в коммите, на который я ссылаюсь, вы можете получить больше информации о том, где находятся эти файлы.

Не удается скомпилировать

Затем я пытаюсь запустить ./runtest в папке unit и получаю следующее:

andreatino@andreatino-virtual-machine:~/Git/inet/tests/unit$ ./runtest 
opp_test: extracting files from *.test files into work...

Creating Makefile in /home/andreatino/Git/inet/tests/unit/work...
Makefile created, running "make depend" to add dependencies...
Creating dependencies...
IEEE80211ac_MacUtils_MUBundleLength/test.cc
In file included from /home/andreatino/Downloads/omnetpp-5.0/include/platdep/sockets.h:2:0,
                 from ../../../src/inet/common/precompiled.h:19,
                 from ../../../src/inet/common/INETDefs.h:22,
                 from ../../../src/inet/linklayer/ieee80211/mac/AccessCategory.h:23,
                 from ../../../src/inet/linklayer/ieee80211/mac/IMacParameters.h:23,
                 from ./lib/ieee80211ac/MacUtilsTest.h:4,
                 from IEEE80211ac_MacUtils_MUBundleLength/test.cc:4:
/home/andreatino/Downloads/omnetpp-5.0/include/omnetpp/platdep/sockets.h:33:3: error: #error "#include <platdep/sockets.h> must precede <omnetpp.h> (and <platdep/timeutil.h> if present)"
 # error "#include <platdep/sockets.h> must precede <omnetpp.h> (and <platdep/timeutil.h> if present)"
   ^
In file included from IEEE80211ac_MacUtils_MUBundleLength/test.cc:4:0:
./lib/ieee80211ac/MacUtilsTest.h:10:23: error: ‘ieee80211ac’ is not a namespace-name
 using namespace inet::ieee80211ac;
                       ^
./lib/ieee80211ac/MacUtilsTest.h:10:34: error: expected namespace-name before ‘;’ token
 using namespace inet::ieee80211ac;
                                  ^
./lib/ieee80211ac/MacUtilsTest.h:65:9: error: ‘MacUtils’ does not name a type
         MacUtils *utils = nullptr;
         ^
./lib/ieee80211ac/MacUtilsTest.h:66:9: error: ‘Ieee80211acMUBundleFrame’ does not name a type
         Ieee80211acMUBundleFrame *bundleFrame = nullptr;
         ^
./lib/ieee80211ac/MacUtilsTest.h: In member function ‘virtual const inet::MACAddress& inet::test::ieee80211ac::MacUtilsTest::DummyMacParameters::getAddress() const’:
./lib/ieee80211ac/MacUtilsTest.h:30:72: warning: no return statement in function returning non-void [-Wreturn-type]
                 virtual const MACAddress& getAddress() const override {}
                                                                        ^
IEEE80211ac_MacUtils_MUBundleLength/test.cc: At global scope:
IEEE80211ac_MacUtils_MUBundleLength/test.cc:13:25: error: ‘inet::tcp’ has not been declared
 using namespace ::inet::tcp::test::ieee80211ac;
                         ^
IEEE80211ac_MacUtils_MUBundleLength/test.cc:13:36: error: ‘ieee80211ac’ is not a namespace-name
 using namespace ::inet::tcp::test::ieee80211ac;
                                    ^
IEEE80211ac_MacUtils_MUBundleLength/test.cc:13:47: error: expected namespace-name before ‘;’ token
 using namespace ::inet::tcp::test::ieee80211ac;
                                               ^
IEEE80211ac_MacUtils_MUBundleLength/test.cc: In member function ‘virtual void IEEE80211ac_MacUtils_MUBundleLength::Test::activity()’:
IEEE80211ac_MacUtils_MUBundleLength/test.cc:28:1: error: ‘MacUtilsTest’ was not declared in this scope
 MacUtilsTest test = MacUtilsTest();
 ^
IEEE80211ac_MacUtils_MUBundleLength/test.cc:28:1: note: suggested alternative:
In file included from IEEE80211ac_MacUtils_MUBundleLength/test.cc:4:0:
./lib/ieee80211ac/MacUtilsTest.h:25:7: note:   ‘inet::test::ieee80211ac::MacUtilsTest’
 class MacUtilsTest
       ^
IEEE80211ac_MacUtils_MUBundleLength/test.cc:30:1: error: ‘test’ was not declared in this scope
 test.testMaxLengthReturned();
 ^
IEEE80211ac_MacUtils_MUBundleLength/test.cc:30:1: note: suggested alternative:
In file included from IEEE80211ac_MacUtils_MUBundleLength/test.cc:4:0:
./lib/ieee80211ac/MacUtilsTest.h:19:16: note:   ‘inet::test’
 namespace test {
                ^
Makefile:123: recipe for target 'out/gcc-debug//IEEE80211ac_MacUtils_MUBundleLength/test.o' failed
make: *** [out/gcc-debug//IEEE80211ac_MacUtils_MUBundleLength/test.o] Error 1

Я не понимаю, что я делаю не так... или даже что здесь происходит...


person Andry    schedule 27.08.2016    source источник


Ответы (1)


Начиная с OMNeT++ 4.2 <platdep/sockets.h> ДОЛЖЕН предшествовать <omnetpp.h>, как указано в журнале изменений:

https://svn-itec.uni-klu.ac.at/trac2/dash/browser/trunk/omnet_simulation/omnet/doc/API-changes.txt?rev=140#L57

В inet они обеспечили правильный порядок, адаптировав src/makefrag в следующем коммите:

https://github.com/inet-framework/inet/commit/d9abbd1b4df5b9efcfb7a7a7f58e84f29223 >

Итак, вам нужно добавить файл makefrag в ту же папку, что и ваш Makefile, со следующим кодом:

PRECOMPILED_HEADER=<path-to-inet>/src/inet/common/precompiled.h
CFLAGS += -include $(PRECOMPILED_HEADER)

Рассмотрите возможность замены <path-to-inet> вашими путями, например. ../../

ОБНОВЛЕНИЕ: в журнале изменений для OMNeT++ 5.1 Preview 3 подчеркивается, что проблема решена:

Ordering of 'platdep/sockets.h' and 'omnetpp.h' is no longer important. It is recommended to include 'omnetpp.h' first.
person dblock    schedule 09.12.2016
comment
Вау, кое-что мне точно нужно сделать. Спасибо за информацию, я попробую их и дам вам знать! - person Andry; 06.01.2017
comment
Итак, я понимаю ваше предложение, однако, если я добавлю этот makefrag в корневую папку, содержащую мой make-файл, это повлияет на все при компиляции. Разве я не должен делать это только в папке test? Потому что INET уже позаботился о src с makefrag там. Я правильно рассуждаю? - person Andry; 06.01.2017
comment
Так что даже если в папке tests нет папки Makefile? Подводя итог, я думаю, что создавать makefrag в inet неправильно, поэтому я добавлю его в tests. Это правильно? Извините, что так много спрашиваю, просто хочу убедиться, что я не ошибаюсь. - person Andry; 06.01.2017
comment
Это не сработает, если я поставлю makefrag под tests :( - person Andry; 06.01.2017
comment
Не работает, даже если я помещаю файл в корень: inet :( - person Andry; 07.01.2017
comment
Я решил отредактировать runtest в tests/unit, добавив cp makefrag work/ перед вызовом opp_makemake... - person Andry; 07.01.2017
comment
Но вопрос в том, могу ли я добиться этого, не меняя код фреймворка? Мне кажется неразумным, что они не подумали об этом... - person Andry; 07.01.2017