| 
									
										
										
										
											2021-05-27 10:05:19 +10:00
										 |  |  | pwtest_sources = [
 | 
					
						
							|  |  |  |   'pwtest.h',
 | 
					
						
							|  |  |  |   'pwtest-implementation.h',
 | 
					
						
							|  |  |  |   'pwtest.c',
 | 
					
						
							| 
									
										
										
										
											2021-06-10 08:33:36 +10:00
										 |  |  |   'pwtest-compat.c',
 | 
					
						
							| 
									
										
										
										
											2021-05-27 10:05:19 +10:00
										 |  |  | ]
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | pwtest_deps = [
 | 
					
						
							|  |  |  |   pipewire_dep,
 | 
					
						
							|  |  |  |   mathlib,
 | 
					
						
							| 
									
										
										
										
											2021-06-07 13:13:52 +10:00
										 |  |  |   dl_lib,
 | 
					
						
							| 
									
										
										
										
											2021-06-21 11:42:56 +03:00
										 |  |  |   epoll_shim_dep
 | 
					
						
							| 
									
										
										
										
											2021-05-27 10:05:19 +10:00
										 |  |  | ]
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | pwtest_c_args = [
 | 
					
						
							| 
									
										
										
										
											2021-12-28 16:35:20 +01:00
										 |  |  |   '-DBUILD_ROOT="@0@"'.format(meson.project_build_root()),
 | 
					
						
							|  |  |  |   '-DSOURCE_ROOT="@0@"'.format(meson.project_source_root()),
 | 
					
						
							| 
									
										
										
										
											2021-05-27 10:05:19 +10:00
										 |  |  | ]
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | pwtest_inc = [
 | 
					
						
							|  |  |  |   pipewire_inc,
 | 
					
						
							|  |  |  |   configinc,
 | 
					
						
							|  |  |  |   includes_inc,
 | 
					
						
							|  |  |  | ]
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | pwtest_lib = static_library(
 | 
					
						
							|  |  |  |   'pwtest',
 | 
					
						
							|  |  |  |   pwtest_sources,
 | 
					
						
							|  |  |  |   c_args: pwtest_c_args,
 | 
					
						
							|  |  |  |   dependencies: pwtest_deps,
 | 
					
						
							|  |  |  |   include_directories: pwtest_inc,
 | 
					
						
							|  |  |  | )
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-12 08:06:47 +10:00
										 |  |  | test('test-pwtest',
 | 
					
						
							| 
									
										
										
										
											2021-06-10 08:33:36 +10:00
										 |  |  |     executable('test-pwtest',
 | 
					
						
							|  |  |  |                'test-pwtest.c',
 | 
					
						
							|  |  |  |                include_directories: pwtest_inc,
 | 
					
						
							| 
									
										
										
										
											2021-12-28 16:04:06 +01:00
										 |  |  |                dependencies: [ spa_dep ],
 | 
					
						
							| 
									
										
										
										
											2021-06-10 08:33:36 +10:00
										 |  |  |                link_with: pwtest_lib)
 | 
					
						
							|  |  |  | )
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-27 10:05:19 +10:00
										 |  |  | # Compilation only, this is the example file for how pwtest works and most
 | 
					
						
							|  |  |  | # of its tests will fail.
 | 
					
						
							|  |  |  | executable('test-example',
 | 
					
						
							|  |  |  |   'test-example.c',
 | 
					
						
							|  |  |  |   include_directories: pwtest_inc,
 | 
					
						
							| 
									
										
										
										
											2021-12-28 16:04:06 +01:00
										 |  |  |   dependencies: [ spa_dep ],
 | 
					
						
							| 
									
										
										
										
											2021-05-27 10:05:19 +10:00
										 |  |  |   link_with: pwtest_lib)
 | 
					
						
							| 
									
										
										
										
											2021-05-31 15:09:45 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-12 08:06:47 +10:00
										 |  |  | test('test-pw-utils',
 | 
					
						
							| 
									
										
										
										
											2021-06-01 16:28:13 +10:00
										 |  |  |     executable('test-pw-utils',
 | 
					
						
							| 
									
										
										
										
											2021-05-31 15:09:45 +10:00
										 |  |  |                'test-properties.c',
 | 
					
						
							| 
									
										
										
										
											2021-06-01 16:28:13 +10:00
										 |  |  |                'test-array.c',
 | 
					
						
							| 
									
										
										
										
											2021-10-07 13:37:45 +10:00
										 |  |  |                'test-map.c',
 | 
					
						
							| 
									
										
											  
											
												pipewire: mem: pw_memblock_map(): fix pointer when reusing mapping
Previously the pointer was determined as follows:
  mm->this.ptr = SPA_PTROFF(m->ptr, range.start, void);
however, when `pw_map_range` is calculated, `pw_map_range::start` is the offset
from the beginning of the first page, starting at `pw_map_range::offset`.
This works correctly if `memblock_map()` runs because that will map the file
with expected offset, so using `range.start` is correct.
However, when a mapping is reused (i.e. `memblock_find_mapping()`) finds something,
then `range.start` is not necessarily correct. Consider the following example:
  * page size is 10
  * one memblock with size 20 (2 pages)
  * the applications wants to mappings:
    * (offset=5,size=10)
    * (offset=15,size=5)
After the first request from the application, a `mapping` object is created
that covers the first two pages of the memblock: offset=0 and size=20. During
the second request, the calculated `pw_map_range` is as follows:
  { start = 5, offset = 10, size = 10 }
and the only previously created mapping is reused since (0 <= 5) and (10 <= 20). When
the pointer of the mapping is adjusted afterwards it will be incorrect since `m->ptr`
points to byte 0 on page 0 (instead of byte 0 on page 1 -- that is assumed). Thereforce
the two will unexpectedly overlap.
Fix that by using `offset - m->offset` when adjusting the mapping's pointer. Also move
the `range` variable into a smaller scope because it only makes sense there. And add
a test that check the above previously incorrect case.
Fixes: 2caf81c97c0aee ("mem: improve memory handling")
Fixes #4884
											
										 
											2025-09-08 12:47:10 +02:00
										 |  |  |                'test-mempool.c',
 | 
					
						
							| 
									
										
										
										
											2021-08-04 15:05:15 +10:00
										 |  |  |                'test-utils.c',
 | 
					
						
							| 
									
										
										
										
											2021-05-31 15:09:45 +10:00
										 |  |  |                include_directories: pwtest_inc,
 | 
					
						
							| 
									
										
										
										
											2021-12-28 16:04:06 +01:00
										 |  |  |                dependencies: [ spa_dep ],
 | 
					
						
							| 
									
										
										
										
											2021-05-31 15:09:45 +10:00
										 |  |  |                link_with: pwtest_lib)
 | 
					
						
							|  |  |  | )
 | 
					
						
							| 
									
										
										
										
											2021-10-12 08:06:47 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  | test('test-lib',
 | 
					
						
							| 
									
										
										
										
											2021-06-01 16:16:00 +10:00
										 |  |  |     executable('test-lib',
 | 
					
						
							|  |  |  |                'test-lib.c',
 | 
					
						
							|  |  |  |                include_directories: pwtest_inc,
 | 
					
						
							| 
									
										
										
										
											2021-12-28 16:04:06 +01:00
										 |  |  |                dependencies: [ spa_dep ],
 | 
					
						
							| 
									
										
										
										
											2021-06-01 16:16:00 +10:00
										 |  |  |                link_with: pwtest_lib)
 | 
					
						
							|  |  |  | )
 | 
					
						
							| 
									
										
										
										
											2021-10-12 08:06:47 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  | test('test-client',
 | 
					
						
							| 
									
										
										
										
											2021-08-04 15:05:15 +10:00
										 |  |  |     executable('test-client',
 | 
					
						
							|  |  |  |                'test-client.c',
 | 
					
						
							|  |  |  |                include_directories: pwtest_inc,
 | 
					
						
							| 
									
										
										
										
											2021-12-28 16:04:06 +01:00
										 |  |  |                dependencies: [ spa_dep ],
 | 
					
						
							| 
									
										
										
										
											2021-08-04 15:05:15 +10:00
										 |  |  |                link_with: pwtest_lib)
 | 
					
						
							|  |  |  | )
 | 
					
						
							| 
									
										
										
										
											2021-10-12 08:06:47 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-08 11:08:16 +01:00
										 |  |  | test('test-loop',
 | 
					
						
							|  |  |  |     executable('test-loop',
 | 
					
						
							|  |  |  |                'test-loop.c',
 | 
					
						
							|  |  |  |                include_directories: pwtest_inc,
 | 
					
						
							| 
									
										
										
										
											2024-09-21 20:33:34 +03:00
										 |  |  |                dependencies: [ spa_dep, epoll_shim_dep ],
 | 
					
						
							| 
									
										
										
										
											2022-02-08 11:08:16 +01:00
										 |  |  |                link_with: pwtest_lib)
 | 
					
						
							|  |  |  | )
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-26 15:11:54 +01:00
										 |  |  | if get_option('spa-plugins').allowed()
 | 
					
						
							| 
									
										
										
										
											2021-10-12 08:06:47 +10:00
										 |  |  | test('test-context',
 | 
					
						
							| 
									
										
										
										
											2021-06-04 11:15:04 +10:00
										 |  |  |     executable('test-context',
 | 
					
						
							|  |  |  |                'test-context.c',
 | 
					
						
							| 
									
										
										
										
											2021-07-06 11:04:44 +10:00
										 |  |  |                'test-config.c',
 | 
					
						
							| 
									
										
										
										
											2021-06-04 11:15:04 +10:00
										 |  |  |                include_directories: pwtest_inc,
 | 
					
						
							| 
									
										
										
										
											2021-12-28 16:04:06 +01:00
										 |  |  |                dependencies: [spa_dep, spa_support_dep, spa_dbus_dep],
 | 
					
						
							| 
									
										
										
										
											2021-08-04 20:38:30 +02:00
										 |  |  |                link_with: [pwtest_lib,
 | 
					
						
							|  |  |  |                             pipewire_module_protocol_native,
 | 
					
						
							|  |  |  |                             pipewire_module_client_node,
 | 
					
						
							|  |  |  |                             pipewire_module_client_device,
 | 
					
						
							|  |  |  |                             pipewire_module_adapter,
 | 
					
						
							|  |  |  |                             pipewire_module_metadata,
 | 
					
						
							|  |  |  |                             pipewire_module_session_manager])
 | 
					
						
							| 
									
										
										
										
											2021-06-04 11:15:04 +10:00
										 |  |  | )
 | 
					
						
							| 
									
										
										
										
											2021-09-14 14:49:03 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-12 08:06:47 +10:00
										 |  |  | test('test-support',
 | 
					
						
							| 
									
										
										
										
											2021-06-04 16:07:01 +10:00
										 |  |  |     executable('test-support',
 | 
					
						
							|  |  |  |                'test-support.c',
 | 
					
						
							|  |  |  |                'test-logger.c',
 | 
					
						
							|  |  |  |                include_directories: pwtest_inc,
 | 
					
						
							| 
									
										
										
										
											2021-12-28 16:04:06 +01:00
										 |  |  |                dependencies: [spa_dep, systemd_dep, spa_support_dep, spa_journal_dep],
 | 
					
						
							| 
									
										
										
										
											2021-09-20 08:59:49 +10:00
										 |  |  |                link_with: [pwtest_lib])
 | 
					
						
							| 
									
										
										
										
											2021-06-04 16:07:01 +10:00
										 |  |  | )
 | 
					
						
							| 
									
										
										
										
											2024-01-26 15:11:54 +01:00
										 |  |  | endif
 | 
					
						
							| 
									
										
										
										
											2021-10-12 08:06:47 +10:00
										 |  |  | test('test-spa',
 | 
					
						
							| 
									
										
										
										
											2021-06-03 11:35:26 +10:00
										 |  |  |     executable('test-spa',
 | 
					
						
							|  |  |  |                'test-spa-buffer.c',
 | 
					
						
							| 
									
										
										
										
											2024-07-29 09:05:13 +02:00
										 |  |  |                'test-spa-control.c',
 | 
					
						
							| 
									
										
										
										
											2021-06-03 11:35:26 +10:00
										 |  |  |                'test-spa-json.c',
 | 
					
						
							| 
									
										
										
										
											2021-06-08 20:00:36 +10:00
										 |  |  |                'test-spa-utils.c',
 | 
					
						
							| 
									
										
										
										
											2021-09-09 14:32:43 +10:00
										 |  |  |                'test-spa-log.c',
 | 
					
						
							| 
									
										
										
										
											2021-06-08 20:00:36 +10:00
										 |  |  |                'test-spa-node.c',
 | 
					
						
							|  |  |  |                'test-spa-pod.c',
 | 
					
						
							| 
									
										
										
										
											2021-06-03 11:35:26 +10:00
										 |  |  |                include_directories: pwtest_inc,
 | 
					
						
							| 
									
										
										
										
											2021-12-28 16:04:06 +01:00
										 |  |  |                dependencies: [ spa_dep ],
 | 
					
						
							| 
									
										
										
										
											2021-06-03 11:35:26 +10:00
										 |  |  |                link_with: pwtest_lib)
 | 
					
						
							|  |  |  | )
 | 
					
						
							| 
									
										
										
										
											2021-06-03 14:13:38 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-05 12:21:28 +02:00
										 |  |  | openal_info = find_program('openal-info', required: false)
 | 
					
						
							|  |  |  | if openal_info.found()
 | 
					
						
							|  |  |  |     cdata.set_quoted('OPENAL_INFO_PATH', openal_info.full_path())
 | 
					
						
							|  |  |  | endif
 | 
					
						
							|  |  |  | summary({'openal-info': openal_info.found()}, bool_yn: true, section: 'Functional test programs')
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | pactl = find_program('pactl', required: false)
 | 
					
						
							|  |  |  | if pactl.found()
 | 
					
						
							|  |  |  |     cdata.set_quoted('PACTL_PATH', pactl.full_path())
 | 
					
						
							|  |  |  | endif
 | 
					
						
							|  |  |  | summary({'pactl': pactl.found()}, bool_yn: true, section: 'Functional test programs')
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if default_sm == 'media-session' or default_sm == 'wireplumber'
 | 
					
						
							| 
									
										
										
										
											2025-07-28 22:05:45 +03:00
										 |  |  |   test_functional_c_args = []
 | 
					
						
							|  |  |  |   if get_option('b_sanitize').contains('address')
 | 
					
						
							|  |  |  |     test_functional_c_args += ['-DHAVE_ASAN']
 | 
					
						
							|  |  |  |   endif
 | 
					
						
							| 
									
										
										
										
											2022-03-05 12:21:28 +02:00
										 |  |  |   test('test-functional',
 | 
					
						
							|  |  |  |     executable('test-functional',
 | 
					
						
							|  |  |  |                'test-functional.c',
 | 
					
						
							|  |  |  |                include_directories: pwtest_inc,
 | 
					
						
							| 
									
										
										
										
											2025-07-28 22:05:45 +03:00
										 |  |  |                c_args: [test_functional_c_args],
 | 
					
						
							| 
									
										
										
										
											2022-03-05 12:21:28 +02:00
										 |  |  |                dependencies: [ spa_dep ],
 | 
					
						
							|  |  |  |                link_with: pwtest_lib)
 | 
					
						
							|  |  |  |   )
 | 
					
						
							|  |  |  | endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-03 14:13:38 +10:00
										 |  |  | valgrind = find_program('valgrind', required: false)
 | 
					
						
							| 
									
										
										
										
											2021-06-29 11:17:03 +03:00
										 |  |  | summary({'valgrind (test setup)': valgrind.found()}, bool_yn: true, section: 'Optional programs')
 | 
					
						
							| 
									
										
										
										
											2021-06-03 14:13:38 +10:00
										 |  |  | if valgrind.found()
 | 
					
						
							| 
									
										
										
										
											2021-10-12 09:22:31 +10:00
										 |  |  |   valgrind_env = environment({'PIPEWIRE_DEBUG': 'D'})
 | 
					
						
							| 
									
										
										
										
											2021-06-03 14:13:38 +10:00
										 |  |  |   add_test_setup('valgrind',
 | 
					
						
							|  |  |  |                  exe_wrapper : [ valgrind,
 | 
					
						
							|  |  |  |                    '--leak-check=full',
 | 
					
						
							|  |  |  |                    '--gen-suppressions=all',
 | 
					
						
							|  |  |  |                    '--error-exitcode=3',
 | 
					
						
							|  |  |  |                    ],
 | 
					
						
							|  |  |  |                  env :  valgrind_env,
 | 
					
						
							| 
									
										
										
										
											2021-06-09 19:38:49 +10:00
										 |  |  |                  timeout_multiplier : 3)
 | 
					
						
							| 
									
										
										
										
											2021-06-03 14:13:38 +10:00
										 |  |  | endif
 |