summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPrzemyslaw Czarnowski <przemyslaw.hawrylewicz.czarnowski@intel.com>2022-02-14 12:26:50 +0300
committerGitHub <noreply@github.com>2022-02-14 12:26:50 +0300
commit1fb7beae5e97aadf8471ae7b6e07f5c2e5f33c78 (patch)
treefc905cdb67494c5b7b59cb21465483f6d0464b31
parent6df74a76eeacc5240d36fa7e62717cd1cdd238a7 (diff)
downloadvirtual-media-1fb7beae5e97aadf8471ae7b6e07f5c2e5f33c78.tar.xz
Switch the build system to meson
Due to requirements from community, new projects have to be built with meson. To unify with other projects some additional warnings has been enabled, so appropriate code updates has been implemented. This commit makes both meson and CMake available to simplyfy transition in openbmc. CMake support will be removed after switching to meson in openbmc will be accepted. Tested: Compiled and smoke tested. Signed-off-by: Przemyslaw Czarnowski <przemyslaw.hawrylewicz.czarnowski@intel.com>
-rw-r--r--.clang-tidy260
-rw-r--r--.gitignore24
-rw-r--r--meson.build228
-rw-r--r--meson_options.txt2
-rw-r--r--src/configuration.hpp2
-rw-r--r--src/events.hpp10
-rw-r--r--src/logger.hpp7
-rw-r--r--src/state/activating_state.cpp47
-rw-r--r--src/state/initial_state.hpp5
-rw-r--r--src/system.hpp2
-rw-r--r--src/utils.hpp5
-rw-r--r--subprojects/boost.wrap7
-rw-r--r--subprojects/gtest.wrap3
-rw-r--r--subprojects/nlohmann.wrap3
-rw-r--r--subprojects/packagefiles/boost/meson.build44
-rw-r--r--subprojects/sdbusplus.wrap3
-rw-r--r--tests/meson.build48
-rw-r--r--tests/src/main.cpp7
18 files changed, 666 insertions, 41 deletions
diff --git a/.clang-tidy b/.clang-tidy
new file mode 100644
index 0000000..dac3299
--- /dev/null
+++ b/.clang-tidy
@@ -0,0 +1,260 @@
+Checks: '
+-*,
+readability-identifier-naming,
+clang-analyzer-apiModeling.StdCLibraryFunctions,
+clang-analyzer-apiModeling.TrustNonnull,
+clang-analyzer-apiModeling.google.GTest,
+clang-analyzer-apiModeling.llvm.CastValue,
+clang-analyzer-apiModeling.llvm.ReturnValue,
+clang-analyzer-core.CallAndMessageModeling,
+clang-analyzer-core.DivideZero,
+clang-analyzer-core.DynamicTypePropagation,
+clang-analyzer-core.NonNullParamChecker,
+clang-analyzer-core.NonnilStringConstants,
+clang-analyzer-core.NullDereference,
+clang-analyzer-core.StackAddrEscapeBase,
+clang-analyzer-core.StackAddressEscape,
+clang-analyzer-core.UndefinedBinaryOperatorResult,
+clang-analyzer-core.VLASize,
+clang-analyzer-core.builtin.BuiltinFunctions,
+clang-analyzer-core.builtin.NoReturnFunctions,
+clang-analyzer-core.uninitialized.ArraySubscript,
+clang-analyzer-core.uninitialized.Assign,
+clang-analyzer-core.uninitialized.Branch,
+clang-analyzer-core.uninitialized.CapturedBlockVariable,
+clang-analyzer-core.uninitialized.UndefReturn,
+clang-analyzer-cplusplus.InnerPointer,
+clang-analyzer-cplusplus.Move,
+clang-analyzer-cplusplus.NewDelete,
+clang-analyzer-cplusplus.NewDeleteLeaks,
+clang-analyzer-cplusplus.PlacementNew,
+clang-analyzer-cplusplus.PureVirtualCall,
+clang-analyzer-cplusplus.SelfAssignment,
+clang-analyzer-cplusplus.SmartPtrModeling,
+clang-analyzer-cplusplus.VirtualCallModeling,
+clang-analyzer-deadcode.DeadStores,
+clang-analyzer-fuchsia.HandleChecker,
+clang-analyzer-nullability.NullPassedToNonnull,
+clang-analyzer-nullability.NullReturnedFromNonnull,
+clang-analyzer-nullability.NullabilityBase,
+clang-analyzer-nullability.NullableDereferenced,
+clang-analyzer-nullability.NullablePassedToNonnull,
+clang-analyzer-nullability.NullableReturnedFromNonnull,
+clang-analyzer-optin.cplusplus.UninitializedObject,
+clang-analyzer-optin.cplusplus.VirtualCall,
+clang-analyzer-optin.mpi.MPI-Checker,
+clang-analyzer-optin.osx.OSObjectCStyleCast,
+clang-analyzer-optin.osx.cocoa.localizability.EmptyLocalizationContextChecker,
+clang-analyzer-optin.osx.cocoa.localizability.NonLocalizedStringChecker,
+clang-analyzer-optin.performance.GCDAntipattern,
+clang-analyzer-optin.performance.Padding,
+clang-analyzer-optin.portability.UnixAPI,
+clang-analyzer-osx.API,
+clang-analyzer-osx.MIG,
+clang-analyzer-osx.NSOrCFErrorDerefChecker,
+clang-analyzer-osx.NumberObjectConversion,
+clang-analyzer-osx.OSObjectRetainCount,
+clang-analyzer-osx.ObjCProperty,
+clang-analyzer-osx.SecKeychainAPI,
+clang-analyzer-osx.cocoa.AtSync,
+clang-analyzer-osx.cocoa.AutoreleaseWrite,
+clang-analyzer-osx.cocoa.ClassRelease,
+clang-analyzer-osx.cocoa.Dealloc,
+clang-analyzer-osx.cocoa.IncompatibleMethodTypes,
+clang-analyzer-osx.cocoa.Loops,
+clang-analyzer-osx.cocoa.MissingSuperCall,
+clang-analyzer-osx.cocoa.NSAutoreleasePool,
+clang-analyzer-osx.cocoa.NSError,
+clang-analyzer-osx.cocoa.NilArg,
+clang-analyzer-osx.cocoa.NonNilReturnValue,
+clang-analyzer-osx.cocoa.ObjCGenerics,
+clang-analyzer-osx.cocoa.RetainCount,
+clang-analyzer-osx.cocoa.RetainCountBase,
+clang-analyzer-osx.cocoa.RunLoopAutoreleaseLeak,
+clang-analyzer-osx.cocoa.SelfInit,
+clang-analyzer-osx.cocoa.SuperDealloc,
+clang-analyzer-osx.cocoa.UnusedIvars,
+clang-analyzer-osx.cocoa.VariadicMethodTypes,
+clang-analyzer-osx.coreFoundation.CFError,
+clang-analyzer-osx.coreFoundation.CFNumber,
+clang-analyzer-osx.coreFoundation.CFRetainRelease,
+clang-analyzer-osx.coreFoundation.containers.OutOfBounds,
+clang-analyzer-osx.coreFoundation.containers.PointerSizedValues,
+clang-analyzer-security.FloatLoopCounter,
+clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling,
+clang-analyzer-security.insecureAPI.SecuritySyntaxChecker,
+clang-analyzer-security.insecureAPI.UncheckedReturn,
+clang-analyzer-security.insecureAPI.bcmp,
+clang-analyzer-security.insecureAPI.bcopy,
+clang-analyzer-security.insecureAPI.bzero,
+clang-analyzer-security.insecureAPI.decodeValueOfObjCType,
+clang-analyzer-security.insecureAPI.getpw,
+clang-analyzer-security.insecureAPI.gets,
+clang-analyzer-security.insecureAPI.mkstemp,
+clang-analyzer-security.insecureAPI.mktemp,
+clang-analyzer-security.insecureAPI.rand,
+clang-analyzer-security.insecureAPI.strcpy,
+clang-analyzer-security.insecureAPI.vfork,
+clang-analyzer-unix.API,
+clang-analyzer-unix.DynamicMemoryModeling,
+clang-analyzer-unix.Malloc,
+clang-analyzer-unix.MallocSizeof,
+clang-analyzer-unix.MismatchedDeallocator,
+clang-analyzer-unix.Vfork,
+clang-analyzer-unix.cstring.BadSizeArg,
+clang-analyzer-unix.cstring.CStringModeling,
+clang-analyzer-unix.cstring.NullArg,
+clang-analyzer-valist.CopyToSelf,
+clang-analyzer-valist.Uninitialized,
+clang-analyzer-valist.Unterminated,
+clang-analyzer-valist.ValistBase,
+clang-analyzer-webkit.NoUncountedMemberChecker,
+clang-analyzer-webkit.RefCntblBaseVirtualDtor,
+cert-con36-c,
+cert-con54-cpp,
+cert-dcl03-c,
+cert-dcl16-c,
+cert-dcl21-cpp,
+cert-dcl37-c,
+cert-dcl50-cpp,
+cert-dcl51-cpp,
+cert-dcl54-cpp,
+cert-dcl58-cpp,
+cert-dcl59-cpp,
+cert-env33-c,
+cert-err09-cpp,
+cert-err34-c,
+cert-err52-cpp,
+cert-err60-cpp,
+cert-err61-cpp,
+cert-fio38-c,
+cert-flp30-c,
+cert-mem57-cpp,
+cert-msc30-c,
+cert-msc32-c,
+cert-msc50-cpp,
+cert-msc51-cpp,
+cert-oop11-cpp,
+cert-oop54-cpp,
+cert-oop57-cpp,
+modernize-avoid-bind,
+modernize-deprecated-headers,
+modernize-deprecated-ios-base-aliases,
+modernize-loop-convert,
+modernize-make-shared,
+modernize-make-unique,
+modernize-raw-string-literal,
+modernize-replace-auto-ptr,
+modernize-replace-random-shuffle,
+modernize-return-braced-init-list,
+modernize-shrink-to-fit,
+modernize-unary-static-assert,
+modernize-use-bool-literals,
+modernize-use-default-member-init,
+modernize-use-emplace,
+modernize-use-equals-default,
+modernize-use-equals-delete,
+modernize-use-noexcept,
+modernize-use-nullptr,
+modernize-use-override,
+modernize-use-transparent-functors,
+modernize-use-uncaught-exceptions,
+modernize-use-using,
+bugprone-argument-comment,
+bugprone-assert-side-effect,
+bugprone-bad-signal-to-kill-thread,
+bugprone-bool-pointer-implicit-conversion,
+bugprone-branch-clone,
+bugprone-copy-constructor-init,
+bugprone-dangling-handle,
+bugprone-dynamic-static-initializers,
+bugprone-fold-init-type,
+bugprone-forward-declaration-namespace,
+bugprone-forwarding-reference-overload,
+bugprone-inaccurate-erase,
+bugprone-incorrect-roundings,
+bugprone-infinite-loop,
+bugprone-integer-division,
+bugprone-lambda-function-name,
+bugprone-macro-parentheses,
+bugprone-macro-repeated-side-effects,
+bugprone-misplaced-operator-in-strlen-in-alloc,
+bugprone-misplaced-pointer-arithmetic-in-alloc,
+bugprone-misplaced-widening-cast,
+bugprone-multiple-statement-macro,
+bugprone-narrowing-conversions,
+bugprone-no-escape,
+bugprone-not-null-terminated-result,
+bugprone-parent-virtual-call,
+bugprone-posix-return,
+bugprone-reserved-identifier,
+bugprone-signed-char-misuse,
+bugprone-sizeof-container,
+bugprone-sizeof-expression,
+bugprone-spuriously-wake-up-functions,
+bugprone-string-constructor,
+bugprone-string-integer-assignment,
+bugprone-string-literal-with-embedded-nul,
+bugprone-suspicious-enum-usage,
+bugprone-suspicious-include,
+bugprone-suspicious-memset-usage,
+bugprone-suspicious-missing-comma,
+bugprone-suspicious-semicolon,
+bugprone-suspicious-string-compare,
+bugprone-swapped-arguments,
+bugprone-terminating-continue,
+bugprone-throw-keyword-missing,
+bugprone-too-small-loop-variable,
+bugprone-undefined-memory-manipulation,
+bugprone-undelegated-constructor,
+bugprone-unhandled-self-assignment,
+bugprone-unused-raii,
+bugprone-unused-return-value,
+bugprone-use-after-move,
+bugprone-virtual-near-miss,
+misc-misplaced-const,
+misc-no-recursion,
+misc-redundant-expression,
+misc-static-assert,
+misc-throw-by-value-catch-by-reference,
+misc-unconventional-assign-operator,
+misc-uniqueptr-reset-release,
+misc-unused-using-decls,
+performance-for-range-copy,
+performance-implicit-conversion-in-loop,
+performance-inefficient-algorithm,
+performance-inefficient-vector-operation,
+performance-move-constructor-init,
+performance-no-automatic-move,
+performance-trivially-destructible,
+performance-type-promotion-in-math-fn,
+performance-unnecessary-copy-initialization,
+performance-faster-string-find,
+performance-for-range-copy,
+performance-implicit-conversion-in-loop,
+performance-inefficient-algorithm,
+performance-inefficient-string-concatenation,
+performance-inefficient-vector-operation,
+performance-move-const-arg,
+performance-move-constructor-init,
+performance-no-automatic-move,
+performance-noexcept-move-constructor,
+performance-trivially-destructible,
+performance-type-promotion-in-math-fn,
+performance-unnecessary-copy-initialization,
+performance-unnecessary-value-param,
+readability-identifier-naming,
+readability-braces-around-statements,
+readability-const-return-type,
+readability-delete-null-pointer,
+readability-deleted-default,
+readability-else-after-return'
+WarningsAsErrors: '*'
+HeaderFilterRegex: '^((?!linux).)*$'
+CheckOptions:
+ - { key: readability-identifier-naming.ClassCase, value: CamelCase }
+ - { key: readability-identifier-naming.VariableCase, value: camelBack }
+ - { key: readability-identifier-naming.FunctionCase, value: camelBack }
+ - { key: readability-identifier-naming.ParameterCase, value: camelBack }
+ - { key: readability-identifier-naming.NamespaceCase, value: lower_case }
+ - { key: readability-identifier-naming.StructCase, value: CamelCase }
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..2e19e70
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,24 @@
+### Meson ###
+# subproject directories
+/subprojects/*
+!/subprojects/*.wrap
+!/subprojects/packagefiles
+
+# Meson Directories
+meson-logs
+meson-private
+
+# Meson Files
+meson_benchmark_setup.dat
+meson_test_setup.dat
+sanitycheckcpp.cc # C++ specific
+sanitycheckcpp.exe # C++ specific
+
+# Ninja
+build.ninja
+.ninja_deps
+.ninja_logs
+# Misc
+compile_commands.json
+
+build*/*
diff --git a/meson.build b/meson.build
new file mode 100644
index 0000000..ad24d31
--- /dev/null
+++ b/meson.build
@@ -0,0 +1,228 @@
+project(
+ 'virtual-media',
+ 'cpp',
+ default_options: [
+ 'warning_level=3',
+ 'werror=true',
+ 'cpp_std=c++20',
+ 'cpp_rtti=false',
+ ],
+ license: 'Apache-2.0',
+ version: '0.1',
+)
+
+if get_option('cpp_std') != 'c++20'
+ error('This project requires c++20 support')
+endif
+
+cxx = meson.get_compiler('cpp')
+
+build = get_option('buildtype')
+optimization = get_option('optimization')
+summary('Build Type',build, section : 'Build Info')
+summary('Optimization',optimization, section : 'Build Info')
+
+#remove debug information for minsize buildtype
+if(get_option('buildtype') == 'minsize')
+ add_project_arguments('-DNDEBUG', language : 'cpp')
+endif
+
+#Disable lto when compiling with no optimization
+if(get_option('optimization') == '0')
+ add_project_arguments('-fno-lto', language: 'cpp')
+ message('Disabling lto & its supported features as optimization is disabled')
+endif
+
+incdir = include_directories('src')
+
+add_project_arguments(
+ cxx.get_supported_arguments([
+ '-Wold-style-cast',
+ '-Wcast-align',
+ '-Wunused',
+ '-Wunused-parameter',
+ '-Wconversion',
+ '-Wsign-conversion',
+ '-Wno-attributes',
+ ]),
+ language: 'cpp'
+)
+
+# temporarily disable those flags until async dbus fixes are not merged
+# See http://goto.intel.com/async-dbus-pr for status
+add_project_arguments(
+ cxx.get_supported_arguments([
+ '-Wno-missing-field-initializers',
+ '-Wno-unused-parameter',
+ '-Wno-unused',
+ ]),
+ language: 'cpp'
+)
+
+if (cxx.get_id() == 'clang' and cxx.version().version_compare('>9.0'))
+add_project_arguments(
+ cxx.get_supported_arguments([
+ '-Weverything',
+ '-Wno-c++98-compat',
+ '-Wno-c++98-compat-pedantic',
+ '-Wno-global-constructors',
+ '-Wno-exit-time-destructors',
+ '-Wno-shadow',
+ '-Wno-used-but-marked-unused',
+ '-Wno-documentation-unknown-command',
+ '-Wno-weak-vtables',
+ '-Wno-documentation',
+ '-Wno-padded',
+ '-Wcovered-switch-default',
+ '-Wcomma',
+ '-Wextra-semi',
+ '-Wzero-as-null-pointer-constant',
+ '-Wswitch-enum',
+ '-Wnull-dereference',
+ '-Wdouble-promotion',
+ '-Wformat=2',
+ ]),
+ language:'cpp')
+endif
+
+if (cxx.get_id() == 'gcc' and cxx.version().version_compare('>8.0'))
+ add_project_arguments(
+ cxx.get_supported_arguments([
+ '-Wduplicated-cond',
+ '-Wduplicated-branches',
+ '-Wlogical-op',
+ '-Wnull-dereference',
+ '-Wdouble-promotion',
+ '-Wformat=2',
+ ]),
+ language:'cpp')
+
+ if (get_option('buildtype') != 'plain')
+ if (get_option('b_lto') == true and get_option('optimization')!='0')
+#Reduce the binary size by removing unnecessary
+#dynamic symbol table entries
+
+ add_project_arguments(
+ cxx.get_supported_arguments([
+ '-fno-fat-lto-objects',
+ '-fvisibility=hidden',
+ '-fvisibility-inlines-hidden'
+ ]),
+ language: 'cpp')
+
+ if cxx.has_link_argument('-Wl,--exclude-libs,ALL')
+ add_project_link_arguments('-Wl,--exclude-libs,ALL', language: 'cpp')
+ endif
+ endif
+ endif
+endif
+
+security_flags = [
+'-fstack-protector-strong',
+'-fPIE',
+'-fPIC',
+'-D_FORTIFY_SOURCE=2',
+'-Wformat',
+'-Wformat-security'
+]
+
+## Add security flags for builds of type 'release','debugoptimized' and 'minsize'
+
+if not (get_option('buildtype') == 'plain' or get_option('buildtype').startswith('debug'))
+ add_project_arguments(
+ cxx.get_supported_arguments([
+ security_flags
+ ]),
+ language: 'cpp')
+endif
+
+systemd = dependency('systemd')
+udev = dependency('udev')
+# this will add appopriate udev library linkage to executable.
+udev_lib_dep = declare_dependency(link_args: ['-ludev'])
+
+
+if cxx.has_header('nlohmann/json.hpp')
+ nlohmann_json = declare_dependency()
+else
+ nlohmann_json_proj = subproject('nlohmann', required: true)
+ nlohmann_json = nlohmann_json_proj.get_variable('nlohmann_json_dep')
+ nlohmann_json = nlohmann_json.as_system('system')
+endif
+
+sdbusplus = dependency('sdbusplus', required: false)
+if not sdbusplus.found()
+ sdbusplus_proj = subproject('sdbusplus', required: true)
+ sdbusplus = sdbusplus_proj.get_variable('sdbusplus_dep')
+ sdbusplus = sdbusplus.as_system('system')
+endif
+
+boost = dependency('boost',
+ modules: ['coroutine', 'iostreams', 'filesystem',
+ 'program_options', 'regex', 'system'],
+ version: '>=1.77',
+ fallback : ['boost', 'boost_dep'],
+ static: false,
+ required: true)
+
+
+add_project_arguments(
+cxx.get_supported_arguments([
+'-DBOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT',
+'-DBOOST_ASIO_DISABLE_THREADS',
+'-DBOOST_NO_RTTI',
+'-DBOOST_NO_TYPEID',
+'-DBOOST_ALLOW_DEPRECATED_HEADERS'
+]),
+language : 'cpp')
+
+systemd_system_unit_dir = systemd.get_pkgconfig_variable(
+ 'systemdsystemunitdir'
+)
+
+
+configure_file(input: 'xyz.openbmc_project.VirtualMedia.service',
+ output: 'xyz.openbmc_project.VirtualMedia.service',
+ install_dir: systemd_system_unit_dir,
+ copy: true,
+ install: true)
+
+configure_file(input : 'tmpfiles.d/virtual-media.conf',
+ output : 'virtual-media.conf',
+ copy : true,
+ install_dir: '/etc/tmpfiles.d',
+ install : true)
+
+configure_file(input : 'virtual-media.json',
+ output : 'virtual-media.json',
+ copy : true,
+ install_dir: '/etc/',
+ install : true)
+
+srcfiles_app = [ 'src/main.cpp',
+ 'src/resources.cpp',
+ 'src/state/activating_state.cpp',
+ ]
+
+bindir = get_option('prefix') + '/' +get_option('bindir')
+
+if get_option('legacy-mode').enabled()
+ add_project_arguments(
+ cxx.get_supported_arguments([
+ '-DLEGACY_MODE_ENABLED=ON',]),
+ language: 'cpp')
+endif
+
+executable('virtual-media',
+ srcfiles_app,
+ dependencies: [ systemd, boost, udev, udev_lib_dep,
+ sdbusplus, nlohmann_json,
+ ],
+ include_directories: incdir,
+ install: true,
+ install_dir:bindir)
+
+#Tests are placed in the tests folder, with it's own meson.build
+if (get_option('tests').enabled())
+ subdir('tests')
+endif
diff --git a/meson_options.txt b/meson_options.txt
new file mode 100644
index 0000000..9f002e3
--- /dev/null
+++ b/meson_options.txt
@@ -0,0 +1,2 @@
+option('tests', type: 'feature', value: 'enabled', description: 'Build unit tests.',)
+option('legacy-mode', type: 'feature', value: 'enabled', description: 'Enable Legacy mode (HTTPs/CIFS support',)
diff --git a/src/configuration.hpp b/src/configuration.hpp
index c29e133..efdddf2 100644
--- a/src/configuration.hpp
+++ b/src/configuration.hpp
@@ -218,7 +218,7 @@ class Configuration
{
mp.mode = Configuration::Mode::proxy;
}
-#if LEGACY_MODE_ENABLED
+#ifdef LEGACY_MODE_ENABLED
else if (*value == 1)
{
mp.mode = Configuration::Mode::legacy;
diff --git a/src/events.hpp b/src/events.hpp
index 320d344..03d0c50 100644
--- a/src/events.hpp
+++ b/src/events.hpp
@@ -11,8 +11,6 @@ struct BasicEvent
{
}
- virtual ~BasicEvent() = default;
-
const char* eventName;
};
@@ -22,7 +20,7 @@ struct RegisterDbusEvent : public BasicEvent
std::shared_ptr<sdbusplus::asio::connection> bus,
std::shared_ptr<sdbusplus::asio::object_server> objServer) :
BasicEvent(__FUNCTION__),
- bus(bus), objServer(objServer)
+ bus(std::move(bus)), objServer(std::move(objServer))
{
}
@@ -40,14 +38,16 @@ struct MountEvent : public BasicEvent
}
MountEvent(const MountEvent&) = delete;
- MountEvent(MountEvent&& other) :
+
+ MountEvent(MountEvent&& other) noexcept :
BasicEvent(__FUNCTION__), target(std::move(other.target))
{
other.target = std::nullopt;
}
MountEvent& operator=(const MountEvent&) = delete;
- MountEvent& operator=(MountEvent&& other)
+
+ MountEvent& operator=(MountEvent&& other) noexcept
{
target = std::nullopt;
std::swap(target, other.target);
diff --git a/src/logger.hpp b/src/logger.hpp
index 3aef8e2..6086ec4 100644
--- a/src/logger.hpp
+++ b/src/logger.hpp
@@ -47,10 +47,9 @@ struct Critical
template <std::size_t Len>
constexpr const char* baseNameImpl(const char (&str)[Len], std::size_t pos)
{
- return pos == 0 ? str
- : (str[pos] == '/' || str[pos] == '\\')
- ? str + pos + 1
- : baseNameImpl(str, --pos);
+ return pos == 0 ? str
+ : (str[pos] == '/' || str[pos] == '\\') ? str + pos + 1
+ : baseNameImpl(str, --pos);
}
template <std::size_t Len>
diff --git a/src/state/activating_state.cpp b/src/state/activating_state.cpp
index 686de99..c22174f 100644
--- a/src/state/activating_state.cpp
+++ b/src/state/activating_state.cpp
@@ -20,7 +20,9 @@
#include <sdbusplus/asio/object_server.hpp>
ActivatingState::ActivatingState(interfaces::MountPointStateMachine& machine) :
- BasicStateT(machine){};
+ BasicStateT(machine)
+{
+}
std::unique_ptr<BasicState> ActivatingState::onEnter()
{
@@ -63,7 +65,7 @@ std::unique_ptr<BasicState> ActivatingState::activateProxyMode()
"/usr/sbin/nbd-client", machine.getConfig().nbdDevice));
if (!process->spawn(Configuration::MountPoint::toArgs(machine.getConfig()),
- [&machine = machine](int exitCode, bool isReady) {
+ [&machine = machine](int exitCode) {
LogMsg(Logger::Info, machine.getName(),
" process ended.");
machine.getExitCode() = exitCode;
@@ -117,7 +119,7 @@ std::unique_ptr<BasicState> ActivatingState::activateLegacyMode()
{
return mountSmbShare();
}
- else if (isHttpsUrl(machine.getTarget()->imgUrl))
+ if (isHttpsUrl(machine.getTarget()->imgUrl))
{
return mountHttpsShare();
}
@@ -201,7 +203,7 @@ std::unique_ptr<resource::Process>
}
}
- std::string nbd_client =
+ std::string nbdClient =
"/usr/sbin/nbd-client " +
boost::algorithm::join(
Configuration::MountPoint::toArgs(machine.getConfig()), " ");
@@ -213,7 +215,7 @@ std::unique_ptr<resource::Process>
// ... then connect nbd-client to served image
"--run",
- nbd_client,
+ nbdClient,
#if VM_VERBOSE_NBDKIT_LOGS
"--verbose", // swarm of debug logs - only for brave souls
@@ -222,14 +224,14 @@ std::unique_ptr<resource::Process>
if (!machine.getTarget()->rw)
{
- args.push_back("--readonly");
+ args.emplace_back("--readonly");
}
// Insert extra params
args.insert(args.end(), params.begin(), params.end());
- if (!process->spawn(args, [&machine = machine, secret = std::move(secret)](
- int exitCode, [[maybe_unused]] bool isReady) {
+ if (!process->spawn(args, [&machine = machine,
+ secret = std::move(secret)](int exitCode) {
LogMsg(Logger::Info, machine.getName(), " process ended.");
machine.getExitCode() = exitCode;
machine.emitSubprocessStoppedEvent();
@@ -312,17 +314,13 @@ bool ActivatingState::getImagePathFromUrl(const std::string& urlScheme,
*imagePath = imageUrl.substr(urlScheme.size() - 1);
return true;
}
- else
- {
- LogMsg(Logger::Error, "Invalid parameter provied");
- return false;
- }
- }
- else
- {
- LogMsg(Logger::Error, "Provided url does not match scheme");
+
+ LogMsg(Logger::Error, "Invalid parameter provied");
return false;
}
+
+ LogMsg(Logger::Error, "Provided url does not match scheme");
+ return false;
}
bool ActivatingState::isHttpsUrl(const std::string& imageUrl)
@@ -353,16 +351,13 @@ fs::path ActivatingState::getImagePath(const std::string& imageUrl)
if (isHttpsUrl(imageUrl) && getImagePathFromHttpsUrl(imageUrl, &imagePath))
{
- return fs::path(imagePath);
+ return {imagePath};
}
- else if (isCifsUrl(imageUrl) &&
- getImagePathFromCifsUrl(imageUrl, &imagePath))
+ if (isCifsUrl(imageUrl) && getImagePathFromCifsUrl(imageUrl, &imagePath))
{
- return fs::path(imagePath);
- }
- else
- {
- LogMsg(Logger::Error, "Unrecognized url's scheme encountered");
- return fs::path("");
+ return {imagePath};
}
+
+ LogMsg(Logger::Error, "Unrecognized url's scheme encountered");
+ return {""};
}
diff --git a/src/state/initial_state.hpp b/src/state/initial_state.hpp
index a1efeef..324f456 100644
--- a/src/state/initial_state.hpp
+++ b/src/state/initial_state.hpp
@@ -19,7 +19,7 @@ struct InitialState : public BasicStateT<InitialState>
const bool isLegacy =
(machine.getConfig().mode == Configuration::Mode::legacy);
-#if !LEGACY_MODE_ENABLED
+#ifndef LEGACY_MODE_ENABLED
if (isLegacy)
{
return std::make_unique<ReadyState>(machine,
@@ -183,7 +183,8 @@ struct InitialState : public BasicStateT<InitialState>
},
[&config = machine.getConfig()](
[[maybe_unused]] const int& property) -> int {
- return config.remainingInactivityTimeout.count();
+ return static_cast<int>(
+ config.remainingInactivityTimeout.count());
});
iface->initialize();
}
diff --git a/src/system.hpp b/src/system.hpp
index 22f9717..ea88e25 100644
--- a/src/system.hpp
+++ b/src/system.hpp
@@ -428,7 +428,7 @@ class Process : public std::enable_shared_from_this<Process>
" EC: ", child.exit_code(),
" Native: ", child.native_exit_code());
- onExit(child.exit_code(), dev.isReady());
+ onExit(child.exit_code());
});
return true;
}
diff --git a/src/utils.hpp b/src/utils.hpp
index 8eaebfa..587cc41 100644
--- a/src/utils.hpp
+++ b/src/utils.hpp
@@ -231,7 +231,7 @@ class VolatileFile
FileObject(const FileObject&) = delete;
FileObject& operator=(const FileObject&) = delete;
- ssize_t write(void* data, ssize_t nw)
+ ssize_t write(void* data, size_t nw)
{
return ::write(fd, data, nw);
}
@@ -271,7 +271,8 @@ class VolatileFile
{
std::size_t bytesToWrite =
std::min(secretLimit, (size - bytesWritten));
- file.write(buf.data(), bytesToWrite);
+ file.write(buf.data(),
+ static_cast<std::streamsize>(bytesToWrite));
bytesWritten += bytesToWrite;
}
}
diff --git a/subprojects/boost.wrap b/subprojects/boost.wrap
new file mode 100644
index 0000000..71e0382
--- /dev/null
+++ b/subprojects/boost.wrap
@@ -0,0 +1,7 @@
+[wrap-file]
+source_url = https://boostorg.jfrog.io/artifactory/main/release/1.77.0/source/boost_1_77_0.tar.gz
+source_hash = 5347464af5b14ac54bb945dc68f1dd7c56f0dad7262816b956138fc53bcc0131
+source_filename = boost_1_77_0.tar.gz
+
+directory = boost_1_77_0
+patch_directory = boost
diff --git a/subprojects/gtest.wrap b/subprojects/gtest.wrap
new file mode 100644
index 0000000..0d37d2e
--- /dev/null
+++ b/subprojects/gtest.wrap
@@ -0,0 +1,3 @@
+[wrap-git]
+url = https://github.com/google/googletest
+revision = HEAD \ No newline at end of file
diff --git a/subprojects/nlohmann.wrap b/subprojects/nlohmann.wrap
new file mode 100644
index 0000000..a77b7c9
--- /dev/null
+++ b/subprojects/nlohmann.wrap
@@ -0,0 +1,3 @@
+[wrap-git]
+revision = b3e5cb7f20dcc5c806e418df34324eca60d17d4e
+url = https://github.com/nlohmann/json.git
diff --git a/subprojects/packagefiles/boost/meson.build b/subprojects/packagefiles/boost/meson.build
new file mode 100644
index 0000000..f991d36
--- /dev/null
+++ b/subprojects/packagefiles/boost/meson.build
@@ -0,0 +1,44 @@
+project('boost', 'cpp',
+ version: '1.77',
+ meson_version: '>=0.56.0')
+
+cxx = meson.get_compiler('cpp')
+
+# Build if not available
+build_dir = join_paths(meson.current_source_dir(), 'build')
+r = run_command('[','!','-d', build_dir, ']')
+if r.returncode() == 0
+ r = run_command('./bootstrap.sh', '--with-libraries=coroutine,filesystem,iostreams,program_options,regex,system')
+ assert(r.returncode() == 0,
+ 'Bootstrap failed' +
+ '\nstdout: ' + r.stdout().strip() +
+ '\nstderr: ' + r.stderr().strip())
+
+ r = run_command('./b2', 'install','--prefix=build')
+ assert(r.returncode() == 0,
+ 'b2 failed' +
+ '\nstdout: ' + r.stdout().strip() +
+ '\nstderr: ' + r.stderr().strip())
+endif
+
+include_dir = join_paths('build', 'include')
+lib_dir = join_paths(meson.current_source_dir(), 'build', 'lib')
+
+custom_dep = declare_dependency(link_args: ['-L' + lib_dir,
+ '-Wl,-rpath-link,' + lib_dir
+ ])
+
+boost_inc = include_directories(include_dir, is_system:true)
+boost_dep = declare_dependency(
+ include_directories : boost_inc,
+ dependencies : [cxx.find_library('boost_context', dirs: lib_dir, static: true),
+ cxx.find_library('boost_filesystem', dirs: lib_dir, static: true),
+ cxx.find_library('boost_regex', dirs: lib_dir, static: true),
+ cxx.find_library('boost_program_options', dirs: lib_dir, static: true),
+ cxx.find_library('boost_thread', dirs: lib_dir, static: true),
+ cxx.find_library('boost_coroutine', dirs: lib_dir, static: true),
+ cxx.find_library('boost_iostreams', dirs: lib_dir, static: true),
+ custom_dep
+ ])
+
+meson.override_dependency('boost', boost_dep)
diff --git a/subprojects/sdbusplus.wrap b/subprojects/sdbusplus.wrap
new file mode 100644
index 0000000..45ffabb
--- /dev/null
+++ b/subprojects/sdbusplus.wrap
@@ -0,0 +1,3 @@
+[wrap-git]
+url = https://github.com/openbmc/sdbusplus.git
+revision = 95874d930f0bcc8390cd47ab3bb1e5e46db45278
diff --git a/tests/meson.build b/tests/meson.build
new file mode 100644
index 0000000..81c6b3b
--- /dev/null
+++ b/tests/meson.build
@@ -0,0 +1,48 @@
+gtest_dep = dependency('gtest', main: true, version: '>1.11.0', disabler: true, required: false)
+gmock_dep = dependency('gmock', disabler: true, required: false)
+
+if not gtest_dep.found() or not gmock_dep.found()
+ cmake = import('cmake')
+ opt_var = cmake.subproject_options()
+
+ opt_var.add_cmake_defines({'CMAKE_CXX_FLAGS': '-Wno-pedantic'})
+ opt_var.set_override_option('warning_level', '3')
+ opt_var.set_override_option('werror', 'true')
+
+ gtest_proj = cmake.subproject('gtest',
+ options: opt_var,
+ required: true)
+ if gtest_proj.found()
+ gtest_dep = declare_dependency(
+ dependencies: [
+ dependency('threads'),
+ gtest_proj.dependency('gtest')
+ ]
+ )
+ gmock_dep = gtest_proj.dependency('gmock')
+ else
+ assert(
+ not get_option('tests').enabled(),
+ 'Googletest is required if tests are enabled'
+ )
+ endif
+endif
+
+test(
+ 'virtual-media-ut',
+ executable(
+ 'virtual-media-ut',
+ [
+ 'src/main.cpp',
+ ],
+ dependencies: [
+ boost,
+ gmock_dep,
+ gtest_dep,
+ sdbusplus,
+ ],
+ include_directories: ['../src', 'src'],
+ cpp_args : '-DINJECT_MOCKS'
+ ),
+ timeout: 120,
+)
diff --git a/tests/src/main.cpp b/tests/src/main.cpp
new file mode 100644
index 0000000..9bb465e
--- /dev/null
+++ b/tests/src/main.cpp
@@ -0,0 +1,7 @@
+#include <gtest/gtest.h>
+
+int main(int argc, char** argv)
+{
+ ::testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}