Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add modulestest logs to CI report #259

Merged
merged 11 commits into from
Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ jobs:
working-directory: ${{ env.container-workspace }}/build
cmd: ctest

- name: Run modulestest
if: success() || failure()
uses: ./.github/actions/container-exec
with:
container: ${{ steps.container.outputs.id }}
working-directory: ${{ env.container-workspace }}/build/modules/test
cmd: |
mkdir -p /etc/osconfig/
./modulestest --gtest_output=xml:${{ env.container-workspace }}/build/gtest-output/TestRecipes.xml testplate.json

- uses: ./.github/actions/gtest-xml
if: success() || failure()
with:
Expand Down
2 changes: 1 addition & 1 deletion devops/scripts/generate_moduletest_metadata.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ while IFS= read -r line ;

if [ ! -z "$recipepath" ] && [ ! -z "$mimpath" ]; then
# Create entry if both mim+recipe are found
echo "Found '$modulename' module adding to test metadata"
echo "Found '$modulename' module adding to recipe configuration"
json="[{ \"ModulePath\": \"$line\", \"MimPath\": \"$mimpath\", \"TestRecipesPath\": \"$recipepath\" }]"
testJSON=$(echo $testJSON | jq --argjson testMetadata "$json" '. |= . + $testMetadata')
fi
Expand Down
9 changes: 1 addition & 8 deletions src/modules/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

include(GoogleTest)
project(modulestest)

set(CMAKE_CXX_STANDARD 17)
Expand All @@ -15,8 +14,7 @@ target_link_libraries(testfactorylib
parsonlib)

target_include_directories(testfactorylib PUBLIC
${MODULES_INC_DIR}
${PLATFORM_INC_DIR})
${MODULES_INC_DIR})

add_executable(modulestest main.cpp)
target_link_libraries(modulestest gtest gtest_main pthread testfactorylib)
Expand All @@ -37,11 +35,6 @@ else()
)
endif()

gtest_discover_tests(modulestest
EXTRA_ARGS ${CMAKE_CURRENT_BINARY_DIR}/testplate.json
XML_OUTPUT_DIR ${GTEST_OUTPUT_DIR}
)

if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8)
target_link_libraries(modulestest stdc++fs)
endif()
Expand Down
27 changes: 2 additions & 25 deletions src/modules/test/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,30 +45,7 @@
#include "RecipeInvoker.h"
#include "MimParser.h"

constexpr const size_t g_lineLength = 256;

inline void TestLogInfo(const char* log)
{
std::cout << log << std::endl;
}

inline void TestLogInfo(const char* format, const char* args...)
{
char buf[g_lineLength] = {0};
std::snprintf(buf, g_lineLength, format, args);
std::cout << buf << std::endl;
}

inline void TestLogError(const char* log)
{
std::cerr << log << std::endl;
}

inline void TestLogError(const char* format, const char* args...)
{
char buf[g_lineLength] = {0};
std::snprintf(buf, g_lineLength, format, args);
std::cerr << buf << std::endl;
}
#define TestLogInfo(format, ...) printf(format, ##__VA_ARGS__); std::cout << std::endl
AhmedBM marked this conversation as resolved.
Show resolved Hide resolved
#define TestLogError(format, ...) fprintf(stderr, format, ##__VA_ARGS__); std::cerr << std::endl

#endif // MODULESTESTCOMMON_H
123 changes: 123 additions & 0 deletions src/modules/test/ManagementModule.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#ifndef MANAGEMENTMODULE_H
#define MANAGEMENTMODULE_H

// MMI function definitions
using Mmi_GetInfo = int (*)(const char*, MMI_JSON_STRING*, int*);
using Mmi_Free = void (*)(MMI_JSON_STRING);
using Mmi_Open = MMI_HANDLE (*)(const char*, const unsigned int);
using Mmi_Set = int (*)(MMI_HANDLE, const char*, const char*, const MMI_JSON_STRING, const int);
using Mmi_Get = int (*)(MMI_HANDLE, const char*, const char*, MMI_JSON_STRING*, int*);
using Mmi_Close = void (*)(MMI_HANDLE);

class ManagementModule
{
public:
// Lifetime of the operation - see MmiGetInfo Schema for Lifetime property
enum Lifetime
{
Undefined = 0,
KeepAlive = 1,
Short = 2
};

struct Version
{
unsigned int major = 0;
unsigned int minor = 0;
unsigned int patch = 0;
unsigned int tweak = 0;

// Only defining "<" as we are only using that operator in comparisons
bool operator < (const Version &rhs) const
{
return (((major < rhs.major) ||
((major == rhs.major) && (minor < rhs.minor)) ||
((major == rhs.major) && (minor == rhs.minor) && (patch < rhs.patch)) ||
((major == rhs.major) && (minor == rhs.minor) && (patch == rhs.patch) && (tweak < rhs.tweak)))
? true : false);
}

std::string ToString() const
{
std::ostringstream ostream;
ostream << major << "." << minor << "." << patch << "." << tweak;
return ostream.str();
}
};

// Structure maps to the MmiGetInfo JSON Schema - see src/modules/schema/mmi-get-info.schema.json for more info
struct Info
{
std::string name;
std::string description;
std::string manufacturer;
Version version;
std::string versionInfo;
std::vector<std::string> components;
Lifetime lifetime;
std::string licenseUri;
std::string projectUri;
unsigned int userAccount;

static int Deserialize(const rapidjson::Value& object, Info& info);
};

ManagementModule();
ManagementModule(const std::string path);
virtual ~ManagementModule();

virtual int Load();
virtual void Unload();

Info GetInfo() const;

protected:
const std::string m_modulePath;

// The handle retuned by dlopen()
void* m_handle;

// Management Module Interface (MMI) imported functions
Mmi_GetInfo m_mmiGetInfo;
Mmi_Open m_mmiOpen;
Mmi_Close m_mmiClose;
Mmi_Set m_mmiSet;
Mmi_Get m_mmiGet;
Mmi_Free m_mmiFree;

Info m_info;

virtual int CallMmiGetInfo(const char* clientName, MMI_JSON_STRING* payload, int* payloadSizeBytes);
virtual MMI_HANDLE CallMmiOpen(const char* componentName, unsigned int maxPayloadSizeBytes);
virtual void CallMmiClose(MMI_HANDLE handle);
virtual int CallMmiSet(MMI_HANDLE handle, const char* componentName, const char* objectName, const MMI_JSON_STRING payload, const int payloadSizeBytes);
virtual int CallMmiGet(MMI_HANDLE handle, const char* componentName, const char* objectName, MMI_JSON_STRING *payload, int *payloadSizeBytes);

friend class MmiSession;
};

class MmiSession
{
public:
MmiSession(std::shared_ptr<ManagementModule> module, const std::string& clientName, unsigned int maxPayloadSizeBytes = 0);
~MmiSession();

int Open();
void Close();

int Set(const char* componentName, const char* objectName, const MMI_JSON_STRING payload, const int payloadSizeBytes);
int Get(const char* componentName, const char* objectName, MMI_JSON_STRING *payload, int *payloadSizeBytes);

ManagementModule::Info GetInfo();
private:
const std::string m_clientName;
const unsigned int m_maxPayloadSizeBytes;
std::shared_ptr<ManagementModule> m_module;

MMI_HANDLE m_mmiHandle;
};

#endif // MANAGEMENTMODULE_H
4 changes: 2 additions & 2 deletions src/modules/test/recipes/CommandRunnerTests.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
"Payload": "{\"commandId\": \"test1\", \"arguments\": \"echo Hello World\", \"timeout\": 0, \"singleLineTextResult\": true, \"action\": 3}",
"PayloadSizeBytes": 123,
"ExpectedResult": 0,
"WaitSeconds": 10
"WaitSeconds": 5
},
{
"ComponentName": "CommandRunner",
"ObjectName": "commandStatus",
"Desired": false,
"Payload": "{\"commandId\":\"test1\",\"resultCode\":0,\"textResult\":\"Hello World\",\"currentState\":2}",
"Payload": "{\"commandId\":\"test1\",\"resultCode\":0,\"textResult\":\"\",\"currentState\":2}",
"ExpectedResult": 0
}
]