b82c2ce871abf81acbadd765cc881ac4ba157250
[platform/adaptation/npu/trix-engine.git] / packaging / npu-engine.spec
1 %define neexampledir %{_libdir}/npu-engine/bin
2
3 Name:           npu-engine
4 Summary:        NPU Engine
5 Version:        1.0.1
6 Release:        1
7 Group:          System Environment/Daemons
8 Packager:       MyungJoo Ham <myungjoo.ham@samsung.com>
9 License:        Proprietary
10 Source0:        npu-engine-%{version}.tar.gz
11
12 BuildRequires:  meson
13 BuildRequires:  ninja
14
15 BuildRequires:  pkg-config
16
17 BuildRequires:  linux-npu-headers
18
19 # N9 uses libdrm
20 BuildRequires:  pkgconfig(libdrm)
21
22 # NE-CONF uses iniparser
23 BuildRequires:  pkgconfig(iniparser)
24
25 # gtest
26 BuildRequires:  gtest-devel
27
28 # test coverage dependency
29 %if 0%{?test_coverage}
30 BuildRequires:  lcov
31 %endif
32
33 # NPU emulation dependency (used in unittests only)
34 %if 0%{?unit_test}
35 %define enable_npu_emul true
36 BuildRequires:  npu-engine-emul
37
38 %ifarch x86_64
39 %define testdatadir %{_datadir}/npu-engine/testdata
40 BuildRequires:  npu-engine-testdata
41 %endif
42
43 # valgrind requires the same arch with host (x86_64)
44 %if 0%{?use_valgrind}
45 %ifarch x86_64
46 BuildRequires:  valgrind
47 BuildRequires:  glibc-debuginfo
48 %else
49 %undefine use_valgrind
50 %endif
51 %endif
52
53 %else
54 %define enable_npu_emul false
55 %endif
56
57 %global debug_package %{nil}
58 %global __debug_install_post %{nil}
59
60 %description
61 This provides in-NPU software control daemon, NPU-Engine.
62
63 %prep
64 %setup -q
65
66 %build
67
68 # @todo (NYI) build three times for the three different transport plugins for npu-engine
69
70 %if 0%{?test_coverage}
71 CXXFLAGS="${CXXFLAGS} -fprofile-arcs -ftest-coverage"
72 CFLAGS="${CFLAGS} -fprofile-arcs -ftest-coverage"
73 %endif
74
75 meson build --prefix=%{_prefix} --sysconfdir=%{_sysconfdir} --libdir=%{_libdir} --includedir=%{_includedir} --bindir=%{neexampledir} -Denable_npu_emul=%{enable_npu_emul} -Denable_data_manip=true
76 ninja -C build %{?_smp_mflags}
77
78 %install
79
80 # Install Core (NPU-Engine)
81 DESTDIR=%{buildroot} ninja install -C build %{?_smp_mflags}
82
83 # Perform unit tests
84 %check
85 %if 0%{?unit_test}
86   pushd build/tests
87
88   # Run unittests
89   find unittests -maxdepth 1 -type f -perm 0755 -print0 | while IFS= read -r -d $'\0' unittest_exec; do
90   %if 0%{?use_valgrind}
91     valgrind ./${unittest_exec}
92   %else
93     ./${unittest_exec} --gtest_output="xml:${unittest_exec}.xml"
94   %endif
95   done
96   # Run apptests
97   find apptests -maxdepth 1 -type f -perm 0755 -print0 | while IFS= read -r -d $'\0' apptest_exec; do
98   %if 0%{?use_valgrind}
99     valgrind ./${apptest_exec}
100   %else
101     ./${apptest_exec}
102   %endif
103   done
104
105   # Run apptests using actual model files.
106   %ifarch x86_64
107   ./apptests/apptest_example_visa /%{testdatadir}/npubinfmt_v1 > /dev/null
108   ./apptests/apptest_example_visa /%{testdatadir}/npubinfmt_v2 > /dev/null
109   %endif
110
111   popd
112 %endif
113
114 # Analyze test coverage
115 %if 0%{?test_coverage}
116   # 'lcov' generates the date format with UTC time zone by default. Let's replace UTC with KST
117   TZ='Asia/Seoul'; export TZ
118
119   $(pwd)/tools/unittestcoverage.py module $(pwd)/src
120
121   # Get commit info
122   VCS=`cat ${RPM_SOURCE_DIR}/npu-engine.spec | grep "^VCS:" | sed "s|VCS:\\W*\\(.*\\)|\\1|"`
123
124   # Create human readable unit test coverate report web page
125   # Create null gcda files if gcov didn't create it
126   find . -name "*.gcno" -exec sh -c 'touch -a "${1%.gcno}.gcda"' _ {} \;
127   # Generate report
128   lcov -t 'NPU SystemService Unit Test Coverage' -o unittest.info -c -d . -b $(pwd)/src --no-external
129   # Exclude generated files
130   lcov -r unittest.info "*/tools/*" "*/tests/*" "*/meson*/*" -o unittest-filtered.info
131   # Visualize the report
132   genhtml -o result unittest-filtered.info -t "NPU SystemService %{version}-%{release} ${VCS}" --ignore-errors source -p ${RPM_BUILD_DIR}
133
134   # Copy unittest results
135   mkdir -p %{buildroot}%{_datadir}/unittest/
136   cp -r result %{buildroot}%{_datadir}/unittest/
137 %endif
138
139 %files
140 %%defattr(-,root,root,-)
141 %{_libdir}/libnpu-engine.so
142 %{_libdir}/libnpu-engine.a
143 %{_sysconfdir}/npu-engine.ini
144
145 %package devel
146 Summary:        Development Support for NPU Engine Library
147 Requires:       npu-engine = %{version}-%{release}
148 %description devel
149 Developmental packages to develop programs using npu-engine.
150 This contains corresponding header files and .pc pkgconfig file.
151 %files devel
152 %{_includedir}/npu-engine/*.h
153 %{_libdir}/pkgconfig/*.pc
154
155 %package example
156 Summary:  NPU Engine Example Package
157 Requires:       npu-engine = %{version}-%{release}
158 %description example
159 Example application package for NPU Engine, including UnitTests and AppTest with realistic scenarios.
160 %files example
161 %%defattr(-,root,root,-)
162 %{neexampledir}/unittests/*
163 %{neexampledir}/apptests/*
164
165 %package unittest-coverage
166 Summary:  NPU Engine UnitTest Coverage Analysis Result
167 %description unittest-coverage
168 HTML pages of lcov results of NPU Engine generated during rpmbuild
169 %if 0%{?test_coverage}
170 %files unittest-coverage
171 %{_datadir}/unittest/*
172 %endif
173
174 %changelog
175 * Wed Feb 19 2020 Dongju Chae <dongju.chae@samsung.com>
176 - Release of 1.0.1
177
178 * Fri Feb 14 2020 Dongju Chae <dongju.chae@samsung.com>
179 - Release of 1.0.0
180
181 * Fri Feb 07 2020 Dongju Chae <dongju.chae@samsung.com>
182 - Release of 0.0.7
183
184 * Tue Jan 07 2020 Dongju Chae <dongju.chae@samsung.com>
185 - Release of 0.0.6
186
187 * Tue Dec 17 2019 Dongju Chae <dongju.chae@samsung.com>
188 - Release of 0.0.5
189
190 * Thu Nov 28 2019 Wook Song <wook16.song@samsung.com>
191 - Release of 0.0.4
192
193 * Wed Nov 27 2019 Wook Song <wook16.song@samsung.com>
194 - Release of 0.0.3
195
196 * Fri Nov 22 2019 Dongju Chae <dongju.chae@samsung.com>
197 - Release of 0.0.2