Move libpldm test cases into libpldm directory

The test cases for different libraries in this repo are put in the same
test directory.
As a follow up of building libpldm only, move the test cases of libpldm
into libpldm/tests, so that the test cases could be built and run by
libpldm-only option.

Tested: Verify the libpldm tests are built and run by libpldm-only
        option.
        Verify all the tests are built and run without libpldm-only
        option.

Signed-off-by: Lei YU <mine260309@gmail.com>
Change-Id: I097000bef316f787ef1894f1a3feec5089ea081a
diff --git a/.gitignore b/.gitignore
index 012f3f9..8d31869 100644
--- a/.gitignore
+++ b/.gitignore
@@ -71,6 +71,7 @@
 /test/*.gcda
 /test/*.gcno
 /test/vgcore.*
+/libpldm/tests/vgcore.*
 /test/libpldm_base_test
 /test/libpldmresponder_base_test
 /test/libpldm_bios_test
diff --git a/libpldm/meson.build b/libpldm/meson.build
index 9d24b2c..bd10096 100644
--- a/libpldm/meson.build
+++ b/libpldm/meson.build
@@ -62,3 +62,7 @@
   description: 'PLDM protocol encode/decode C lib',
   version: meson.project_version(),
   libraries: libpldm)
+
+if get_option('tests').enabled()
+  subdir('tests')
+endif
diff --git a/libpldm/tests/.clang-format b/libpldm/tests/.clang-format
new file mode 100644
index 0000000..ae9ad39
--- /dev/null
+++ b/libpldm/tests/.clang-format
@@ -0,0 +1,98 @@
+---
+Language:        Cpp
+# BasedOnStyle:  LLVM
+AccessModifierOffset: -2
+AlignAfterOpenBracket: Align
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+AlignEscapedNewlinesLeft: false
+AlignOperands:   true
+AlignTrailingComments: true
+AllowAllParametersOfDeclarationOnNextLine: true
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: None
+AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: true
+BinPackArguments: true
+BinPackParameters: true
+BraceWrapping:
+  AfterClass:      true
+  AfterControlStatement: true
+  AfterEnum:       true
+  AfterFunction:   true
+  AfterNamespace:  true
+  AfterObjCDeclaration: true
+  AfterStruct:     true
+  AfterUnion:      true
+  BeforeCatch:     true
+  BeforeElse:      true
+  IndentBraces:    false
+BreakBeforeBinaryOperators: None
+BreakBeforeBraces: Custom
+BreakBeforeTernaryOperators: true
+BreakConstructorInitializers: AfterColon
+ColumnLimit:     80
+CommentPragmas:  '^ IWYU pragma:'
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerIndentWidth: 4
+ContinuationIndentWidth: 4
+Cpp11BracedListStyle: true
+DerivePointerAlignment: false
+PointerAlignment: Left
+DisableFormat:   false
+ExperimentalAutoDetectBinPacking: false
+FixNamespaceComments: true
+ForEachMacros:   [ foreach, Q_FOREACH, BOOST_FOREACH ]
+IncludeBlocks: Regroup
+IncludeCategories:
+  - Regex:           '^[<"](gtest|gmock)'
+    Priority:        5
+  - Regex:           '^"config.h"'
+    Priority:        -1
+  - Regex:           '^".*\.hpp"'
+    Priority:        1
+  - Regex:           '^<.*\.h>'
+    Priority:        2
+  - Regex:           '^<.*'
+    Priority:        3
+  - Regex:           '.*'
+    Priority:        4
+IndentCaseLabels: true
+IndentWidth:     4
+IndentWrappedFunctionNames: true
+KeepEmptyLinesAtTheStartOfBlocks: true
+MacroBlockBegin: ''
+MacroBlockEnd:   ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+ObjCBlockIndentWidth: 2
+ObjCSpaceAfterProperty: false
+ObjCSpaceBeforeProtocolList: true
+PenaltyBreakBeforeFirstCallParameter: 19
+PenaltyBreakComment: 300
+PenaltyBreakFirstLessLess: 120
+PenaltyBreakString: 1000
+PenaltyExcessCharacter: 1000000
+PenaltyReturnTypeOnItsOwnLine: 60
+ReflowComments:  true
+SortIncludes:    true
+SortUsingDeclarations: true
+SpaceAfterCStyleCast: false
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeParens: ControlStatements
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles:  false
+SpacesInContainerLiterals: true
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+Standard:        Cpp11
+TabWidth:        4
+UseTab:          Never
+...
diff --git a/test/libpldm_base_test.cpp b/libpldm/tests/libpldm_base_test.cpp
similarity index 100%
rename from test/libpldm_base_test.cpp
rename to libpldm/tests/libpldm_base_test.cpp
diff --git a/test/libpldm_bios_table_test.cpp b/libpldm/tests/libpldm_bios_table_test.cpp
similarity index 100%
rename from test/libpldm_bios_table_test.cpp
rename to libpldm/tests/libpldm_bios_table_test.cpp
diff --git a/test/libpldm_bios_test.cpp b/libpldm/tests/libpldm_bios_test.cpp
similarity index 100%
rename from test/libpldm_bios_test.cpp
rename to libpldm/tests/libpldm_bios_test.cpp
diff --git a/test/libpldm_fru_test.cpp b/libpldm/tests/libpldm_fru_test.cpp
similarity index 100%
rename from test/libpldm_fru_test.cpp
rename to libpldm/tests/libpldm_fru_test.cpp
diff --git a/test/libpldm_pdr_test.cpp b/libpldm/tests/libpldm_pdr_test.cpp
similarity index 100%
rename from test/libpldm_pdr_test.cpp
rename to libpldm/tests/libpldm_pdr_test.cpp
diff --git a/test/libpldm_platform_test.cpp b/libpldm/tests/libpldm_platform_test.cpp
similarity index 100%
rename from test/libpldm_platform_test.cpp
rename to libpldm/tests/libpldm_platform_test.cpp
diff --git a/test/libpldm_utils_test.cpp b/libpldm/tests/libpldm_utils_test.cpp
similarity index 100%
rename from test/libpldm_utils_test.cpp
rename to libpldm/tests/libpldm_utils_test.cpp
diff --git a/libpldm/tests/meson.build b/libpldm/tests/meson.build
new file mode 100644
index 0000000..08d2d19
--- /dev/null
+++ b/libpldm/tests/meson.build
@@ -0,0 +1,45 @@
+if get_option('oe-sdk').enabled()
+  # Setup OE SYSROOT
+  OECORE_TARGET_SYSROOT = run_command('sh', '-c', 'echo $OECORE_TARGET_SYSROOT').stdout().strip()
+  if OECORE_TARGET_SYSROOT == ''
+      error('Unable to get $OECORE_TARGET_SYSROOT, check your environment.')
+  endif
+  message('OE_SYSROOT: ' + OECORE_TARGET_SYSROOT)
+  rpath = ':'.join([OECORE_TARGET_SYSROOT + '/lib', OECORE_TARGET_SYSROOT + '/usr/lib'])
+  ld_so = run_command('sh', '-c', 'find ' + OECORE_TARGET_SYSROOT + '/lib/ld-*.so | sort -r -n | head -n1').stdout().strip()
+  dynamic_linker = ['-Wl,-dynamic-linker,' + ld_so]
+else
+  dynamic_linker = []
+endif
+
+gtest = dependency('gtest', main: true, disabler: true, required: true)
+gmock = dependency('gmock', disabler: true, required: true)
+
+tests = [
+  'libpldm_base_test',
+  'libpldm_platform_test',
+  'libpldm_bios_test',
+  'libpldm_bios_table_test',
+  'libpldm_fru_test',
+  'libpldm_utils_test',
+  'libpldm_pdr_test'
+]
+
+if get_option('oem-ibm').enabled()
+  tests += [
+    '../../oem/ibm/test/libpldm_fileio_test',
+  ]
+endif
+
+foreach t : tests
+  test(t, executable(t.underscorify(), t + '.cpp',
+                     implicit_include_directories: false,
+                     link_args: dynamic_linker,
+                     build_rpath: get_option('oe-sdk').enabled() ? rpath : '',
+                     dependencies: [
+                         libpldm,
+                         gtest,
+                         gmock]),
+       workdir: meson.current_source_dir())
+endforeach
+
diff --git a/test/meson.build b/test/meson.build
index 644b7fd..1ae6058 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -17,27 +17,19 @@
 pldmd = declare_dependency(sources: '../instance_id.cpp')
 
 tests = [
-  'libpldm_base_test',
-  'libpldm_platform_test',
   'libpldmresponder_base_test',
-  'libpldm_bios_test',
-  'libpldm_bios_table_test',
   'libpldmresponder_bios_test',
   'libpldmresponder_pdr_state_effecter_test',
   'libpldmresponder_bios_table_test',
   'libpldmresponder_platform_test',
-  'libpldm_fru_test',
-  'libpldm_utils_test',
   'pldmd_instanceid_test',
   'pldmd_registration_test',
   'pldm_utils_test',
   'libpldmresponder_fru_test',
-  'libpldm_pdr_test'
 ]
 
 if get_option('oem-ibm').enabled()
   tests += [
-    '../oem/ibm/test/libpldm_fileio_test',
     '../oem/ibm/test/libpldmresponder_fileio_test'
   ]
 endif