<div dir="ltr">Hi there,<div><br></div><div>I am considering bundling all FreeBSD-specific igt macros into an `igt_freebsd.h` header</div><div>for greater accessibility. If this idea is acceptable, I need a place to create this file.</div><div>What's the appropriate location for an igt-specific header that does not have a corresponding</div><div>source file?</div><div><br></div><div>Thank you,</div><div>Jake Freeland</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Sep 2, 2022 at 9:14 AM Jake Freeland <<a href="mailto:jake@technologyfriends.net">jake@technologyfriends.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Signed-off-by: Jake Freeland <<a href="mailto:jfree@freebsd.org" target="_blank">jfree@freebsd.org</a>><br>
---<br>
benchmarks/gem_exec_tracer.c | 4 +<br>
benchmarks/gem_syslatency.c | 9 ++<br>
include/linux-uapi/sync_file.h | 8 ++<br>
lib/i915/gem_engine_topology.c | 4 +<br>
lib/i915/gem_mman.c | 5 ++<br>
lib/i915/intel_memory_region.c | 4 +<br>
lib/i915/perf.c | 2 +<br>
lib/igt_audio.c | 4 +<br>
lib/igt_aux.c | 44 ++++++++++<br>
lib/igt_aux.h | 6 +-<br>
lib/igt_core.c | 16 +++-<br>
lib/igt_core.h | 6 ++<br>
lib/igt_debugfs.c | 6 ++<br>
lib/igt_device.c | 2 +<br>
lib/igt_device_scan.c | 4 +<br>
lib/igt_eld.c | 4 +<br>
lib/igt_frame.c | 4 +<br>
lib/igt_kmod.c | 118 ++++++++++++++++++++++++++<br>
lib/igt_kmod.h | 2 +<br>
lib/igt_kms.c | 4 +<br>
lib/igt_os.c | 19 +++++<br>
lib/igt_perf.c | 58 +++++++++++++<br>
lib/igt_perf.h | 4 +<br>
lib/igt_pm.c | 2 +<br>
lib/igt_syncobj.c | 4 +<br>
lib/igt_sysfs.c | 2 +<br>
lib/igt_vgem.c | 5 ++<br>
lib/intel_allocator.c | 4 +<br>
lib/intel_batchbuffer.c | 5 ++<br>
lib/sw_sync.c | 4 +<br>
lib/tests/igt_exit_handler.c | 4 +<br>
lib/tests/igt_fork.c | 4 +<br>
lib/tests/igt_tests_common.h | 9 ++<br>
runner/executor.c | 14 +++<br>
tests/core_auth.c | 4 +<br>
tests/drm_import_export.c | 4 +<br>
tests/dumb_buffer.c | 5 ++<br>
tests/i915/gem_close_race.c | 6 ++<br>
tests/i915/gem_concurrent_all.c | 5 ++<br>
tests/i915/gem_create.c | 4 +<br>
tests/i915/gem_ctx_exec.c | 4 +<br>
tests/i915/gem_ctx_persistence.c | 4 +<br>
tests/i915/gem_ctx_shared.c | 4 +<br>
tests/i915/gem_exec_fence.c | 4 +<br>
tests/i915/gem_exec_latency.c | 4 +<br>
tests/i915/gem_lmem_swapping.c | 4 +<br>
tests/i915/gem_madvise.c | 4 +<br>
tests/i915/gem_mmap_gtt.c | 14 +++<br>
tests/i915/gem_mmap_offset.c | 14 +++<br>
tests/i915/gem_shrink.c | 4 +<br>
tests/i915/gem_wait.c | 4 +<br>
tests/i915/i915_hangman.c | 4 +<br>
tests/i915/i915_module_load.c | 2 +<br>
tests/i915/i915_pm_backlight.c | 4 +<br>
tests/i915/i915_pm_rpm.c | 13 +++<br>
tests/i915/sysfs_heartbeat_interval.c | 4 +<br>
tests/kms_content_protection.c | 2 +<br>
tests/kms_cursor_legacy.c | 4 +<br>
tests/kms_flip.c | 4 +<br>
tests/kms_sysfs_edid_timing.c | 4 +<br>
tests/sw_sync.c | 3 +<br>
tests/syncobj_timeline.c | 4 +<br>
tests/syncobj_wait.c | 4 +<br>
tests/tools_test.c | 5 ++<br>
tests/vc4_purgeable_bo.c | 4 +<br>
tests/vc4_wait_bo.c | 4 +<br>
tests/vc4_wait_seqno.c | 4 +<br>
tools/intel_gvtg_test.c | 3 +<br>
68 files changed, 552 insertions(+), 6 deletions(-)<br>
<br>
diff --git a/benchmarks/gem_exec_tracer.c b/benchmarks/gem_exec_tracer.c<br>
index e6973991..084c8e65 100644<br>
--- a/benchmarks/gem_exec_tracer.c<br>
+++ b/benchmarks/gem_exec_tracer.c<br>
@@ -41,6 +41,10 @@<br>
#include "intel_aub.h"<br>
#include "intel_chipset.h"<br>
<br>
+#ifdef __FreeBSD__<br>
+#define _IOC_TYPE(nr) (((nr) >> 8) & 255)<br>
+#endif<br>
+<br>
static int (*libc_close)(int fd);<br>
static int (*libc_ioctl)(int fd, unsigned long request, void *argp);<br>
<br>
diff --git a/benchmarks/gem_syslatency.c b/benchmarks/gem_syslatency.c<br>
index 035ee934..be92ff0f 100644<br>
--- a/benchmarks/gem_syslatency.c<br>
+++ b/benchmarks/gem_syslatency.c<br>
@@ -42,12 +42,21 @@<br>
#include <limits.h><br>
#include "drm.h"<br>
<br>
+#ifdef __linux__<br>
#include <linux/unistd.h><br>
+#elif defined(__FreeBSD__)<br>
+#include <sys/mman.h><br>
+#define MAP_POPULATE MAP_PREFAULT_READ<br>
+#define gettid() getpid()<br>
+#define MADV_HUGEPAGE MADV_SEQUENTIAL<br>
+#endif<br>
<br>
#include "i915/gem_create.h"<br>
#include "i915/gem_ring.h"<br>
<br>
+#ifdef __linux__<br>
#define sigev_notify_thread_id _sigev_un._tid<br>
+#endif<br>
<br>
static volatile int done;<br>
<br>
diff --git a/include/linux-uapi/sync_file.h b/include/linux-uapi/sync_file.h<br>
index b4f2db00..0f1fb720 100644<br>
--- a/include/linux-uapi/sync_file.h<br>
+++ b/include/linux-uapi/sync_file.h<br>
@@ -12,8 +12,16 @@<br>
#ifndef _LINUX_SYNC_H<br>
#define _LINUX_SYNC_H<br>
<br>
+#ifdef __linux__<br>
#include <linux/ioctl.h><br>
#include <linux/types.h><br>
+#elif defined(__FreeBSD__)<br>
+#include <sys/ioctl.h><br>
+#include <sys/types.h><br>
+#define __s32 int32_t<br>
+#define __u32 uint32_t<br>
+#define __u64 uint64_t<br>
+#endif<br>
<br>
/**<br>
* struct sync_merge_data - data passed to merge ioctl<br>
diff --git a/lib/i915/gem_engine_topology.c b/lib/i915/gem_engine_topology.c<br>
index ca3333c2..9d574de5 100644<br>
--- a/lib/i915/gem_engine_topology.c<br>
+++ b/lib/i915/gem_engine_topology.c<br>
@@ -88,6 +88,10 @@<br>
*/<br>
#define SIZEOF_QUERY offsetof(struct drm_i915_query_engine_info, \<br>
engines[GEM_MAX_ENGINES])<br>
+#ifdef __FreeBSD__<br>
+#define SYS_getdents64 SYS_freebsd11_getdents<br>
+#define ino64_t ino_t<br>
+#endif<br>
<br>
static int __gem_query(int fd, struct drm_i915_query *q)<br>
{<br>
diff --git a/lib/i915/gem_mman.c b/lib/i915/gem_mman.c<br>
index aa9ac6f3..7bd6f22b 100644<br>
--- a/lib/i915/gem_mman.c<br>
+++ b/lib/i915/gem_mman.c<br>
@@ -44,6 +44,11 @@<br>
#define VG(x) do {} while (0)<br>
#endif<br>
<br>
+#ifdef __FreeBSD__<br>
+#define mmap64(addr, len, prot, flags, fd, offset) \<br>
+ mmap(addr, len, prot, flags, fd, offset)<br>
+#endif<br>
+<br>
static int gem_mmap_gtt_version(int fd)<br>
{<br>
struct drm_i915_getparam gp;<br>
diff --git a/lib/i915/intel_memory_region.c b/lib/i915/intel_memory_region.c<br>
index 93a18982..88b2667b 100644<br>
--- a/lib/i915/intel_memory_region.c<br>
+++ b/lib/i915/intel_memory_region.c<br>
@@ -21,7 +21,11 @@<br>
* IN THE SOFTWARE.<br>
*/<br>
<br>
+#ifdef __linux__<br>
#include <linux/limits.h><br>
+#elif defined(__FreeBSD__)<br>
+#include <sys/limits.h><br>
+#endif<br>
#include <signal.h><br>
#include <sys/ioctl.h><br>
#include <sys/time.h><br>
diff --git a/lib/i915/perf.c b/lib/i915/perf.c<br>
index d88835ff..beda6b8a 100644<br>
--- a/lib/i915/perf.c<br>
+++ b/lib/i915/perf.c<br>
@@ -29,7 +29,9 @@<br>
#include <fcntl.h><br>
#include <sys/ioctl.h><br>
#include <sys/stat.h><br>
+#ifdef __linux__<br>
#include <sys/sysmacros.h><br>
+#endif<br>
#include <sys/types.h><br>
#include <unistd.h><br>
<br>
diff --git a/lib/igt_audio.c b/lib/igt_audio.c<br>
index e0b1bafe..201a39c6 100644<br>
--- a/lib/igt_audio.c<br>
+++ b/lib/igt_audio.c<br>
@@ -26,6 +26,10 @@<br>
<br>
#include "config.h"<br>
<br>
+#ifdef __FreeBSD__<br>
+#include <limits.h><br>
+#endif<br>
+<br>
#include <errno.h><br>
#include <fcntl.h><br>
#include <gsl/gsl_fft_real.h><br>
diff --git a/lib/igt_aux.c b/lib/igt_aux.c<br>
index edb53425..e6b2bd7e 100644<br>
--- a/lib/igt_aux.c<br>
+++ b/lib/igt_aux.c<br>
@@ -52,7 +52,9 @@<br>
#include <assert.h><br>
#include <grp.h><br>
<br>
+#ifdef __linux__<br>
#include <proc/readproc.h><br>
+#endif<br>
#include <libudev.h><br>
<br>
#include "drmtest.h"<br>
@@ -75,6 +77,12 @@<br>
#include <libgen.h> /* for dirname() */<br>
#endif<br>
<br>
+#ifdef __FreeBSD__<br>
+typedef struct { char state; } proc_t;<br>
+#define gettid() getpid()<br>
+#define setpgrp() setpgid(0, 0)<br>
+#endif<br>
+<br>
/**<br>
* SECTION:igt_aux<br>
* @short_description: Auxiliary libraries and support functions<br>
@@ -1206,6 +1214,7 @@ void igt_unlock_mem(void)<br>
locked_mem = NULL;<br>
}<br>
<br>
+#ifdef __linux__<br>
/**<br>
* igt_is_process_running:<br>
* @comm: Name of process in the form found in /proc/pid/comm (limited to 15<br>
@@ -1780,6 +1789,41 @@ igt_lsof_kill_audio_processes(void)<br>
<br>
return fail;<br>
}<br>
+#elif defined(__FreeBSD__)<br>
+int<br>
+igt_is_process_running(const char *comm)<br>
+{<br>
+ return -ENOSYS;<br>
+}<br>
+<br>
+int<br>
+igt_terminate_process(int sig, const char *comm)<br>
+{<br>
+ return -ENOSYS;<br>
+}<br>
+<br>
+void<br>
+igt_lsof(const char *dpath)<br>
+{<br>
+}<br>
+<br>
+int<br>
+igt_lsof_kill_audio_processes(void)<br>
+{<br>
+ return -ENOSYS;<br>
+}<br>
+<br>
+int<br>
+pipewire_pulse_start_reserve(void)<br>
+{<br>
+ return -ENOSYS;<br>
+}<br>
+<br>
+void<br>
+pipewire_pulse_stop_reserve(void)<br>
+{<br>
+}<br>
+#endif /* __linux__ */<br>
<br>
static struct igt_siglatency {<br>
timer_t timer;<br>
diff --git a/lib/igt_aux.h b/lib/igt_aux.h<br>
index c8d487b6..912f36c1 100644<br>
--- a/lib/igt_aux.h<br>
+++ b/lib/igt_aux.h<br>
@@ -34,9 +34,7 @@<br>
#include <sys/time.h><br>
#include <sys/types.h><br>
#include <unistd.h><br>
-#ifdef __linux__<br>
-# include <sys/syscall.h><br>
-#endif<br>
+#include <sys/syscall.h><br>
<br>
#include <i915/gem_submission.h><br>
<br>
@@ -48,8 +46,8 @@<br>
# ifndef HAVE_GETTID<br>
# define gettid() (pid_t)(syscall(__NR_gettid))<br>
# endif<br>
-#endif<br>
#define sigev_notify_thread_id _sigev_un._tid<br>
+#endif<br>
<br>
/* auxialiary igt helpers from igt_aux.c */<br>
/* generally useful helpers */<br>
diff --git a/lib/igt_core.c b/lib/igt_core.c<br>
index e7425326..23f703f3 100644<br>
--- a/lib/igt_core.c<br>
+++ b/lib/igt_core.c<br>
@@ -43,7 +43,7 @@<br>
#include <unistd.h><br>
#include <sys/wait.h><br>
#include <sys/types.h><br>
-#ifdef __linux__<br>
+#if defined(__linux__) || defined(__FreeBSD__)<br>
#include <sys/syscall.h><br>
#endif<br>
#include <pthread.h><br>
@@ -85,6 +85,12 @@<br>
#include <libgen.h> /* for basename() on Solaris */<br>
#endif<br>
<br>
+#ifdef __FreeBSD__<br>
+#define gettid() getpid()<br>
+#define pthread_sigqueue(pid, signo, value) sigqueue(pid, signo, value)<br>
+#define sighandler_t sig_t<br>
+#endif<br>
+<br>
/**<br>
* SECTION:igt_core<br>
* @short_description: Core i-g-t testing support<br>
@@ -786,6 +792,7 @@ static void print_usage(const char *help_str, bool output_on_stderr)<br>
<br>
static void oom_adjust_for_doom(void)<br>
{<br>
+#ifdef __linux__<br>
int fd;<br>
const char always_kill[] = "1000";<br>
<br>
@@ -793,7 +800,7 @@ static void oom_adjust_for_doom(void)<br>
igt_assert(fd != -1);<br>
igt_assert(write(fd, always_kill, sizeof(always_kill)) == sizeof(always_kill));<br>
close(fd);<br>
-<br>
+#endif<br>
}<br>
<br>
/**<br>
@@ -2223,7 +2230,12 @@ bool __igt_fork_helper(struct igt_helper_process *proc)<br>
igt_assert(0);<br>
case 0:<br>
reset_helper_process_list();<br>
+#ifdef __linux__<br>
oom_adjust_for_doom();<br>
+#elif defined(__FreeBSD__)<br>
+ /* not a great substitution for oom_adjust_for_doom() */<br>
+ raise(SIGTERM);<br>
+#endif<br>
<br>
return true;<br>
default:<br>
diff --git a/lib/igt_core.h b/lib/igt_core.h<br>
index aa98e8ed..7869f722 100644<br>
--- a/lib/igt_core.h<br>
+++ b/lib/igt_core.h<br>
@@ -31,7 +31,9 @@<br>
#define IGT_CORE_H<br>
<br>
#include <assert.h><br>
+#ifdef __linux__<br>
#include <byteswap.h><br>
+#endif<br>
#include <setjmp.h><br>
#include <stdbool.h><br>
#include <stdint.h><br>
@@ -47,6 +49,10 @@<br>
#define IGT_LOG_DOMAIN (NULL)<br>
#endif<br>
<br>
+#ifdef __FreeBSD__<br>
+#include <signal.h><br>
+#define jmp_buf sigjmp_buf<br>
+#endif<br>
<br>
#ifndef STATIC_ANALYSIS_BUILD<br>
#if defined(__clang_analyzer__) || defined(__COVERITY__) || defined(__KLOCWORK__)<br>
diff --git a/lib/igt_debugfs.c b/lib/igt_debugfs.c<br>
index a56688a5..b7e37851 100644<br>
--- a/lib/igt_debugfs.c<br>
+++ b/lib/igt_debugfs.c<br>
@@ -25,7 +25,9 @@<br>
#include <inttypes.h><br>
#include <sys/stat.h><br>
#include <sys/mount.h><br>
+#ifdef __linux__<br>
#include <sys/sysmacros.h><br>
+#endif<br>
#include <dirent.h><br>
#include <errno.h><br>
#include <stdio.h><br>
@@ -43,6 +45,10 @@<br>
#include "igt_debugfs.h"<br>
#include "igt_sysfs.h"<br>
<br>
+#ifdef __FreeBSD__<br>
+#define mount(src, dest, fstype, flags, data) mount(fstype, dest, flags, data)<br>
+#endif<br>
+<br>
/**<br>
* SECTION:igt_debugfs<br>
* @short_description: Support code for debugfs features<br>
diff --git a/lib/igt_device.c b/lib/igt_device.c<br>
index fddfba72..49b77122 100644<br>
--- a/lib/igt_device.c<br>
+++ b/lib/igt_device.c<br>
@@ -25,7 +25,9 @@<br>
#include <fcntl.h><br>
<br>
#include <sys/stat.h><br>
+#ifdef __linux__<br>
#include <sys/sysmacros.h><br>
+#endif<br>
#include "igt.h"<br>
#include "igt_device.h"<br>
#include "igt_sysfs.h"<br>
diff --git a/lib/igt_device_scan.c b/lib/igt_device_scan.c<br>
index eb6b45b8..6a921d52 100644<br>
--- a/lib/igt_device_scan.c<br>
+++ b/lib/igt_device_scan.c<br>
@@ -32,7 +32,11 @@<br>
#include <fcntl.h><br>
#include <glib.h><br>
#include <libudev.h><br>
+#ifdef __linux__<br>
#include <linux/limits.h><br>
+#elif defined(__FreeBSD__)<br>
+#include <limits.h><br>
+#endif<br>
#include <sys/stat.h><br>
#include <sys/time.h><br>
#include <sys/types.h><br>
diff --git a/lib/igt_eld.c b/lib/igt_eld.c<br>
index ef6625df..e05ad6de 100644<br>
--- a/lib/igt_eld.c<br>
+++ b/lib/igt_eld.c<br>
@@ -23,6 +23,10 @@<br>
* Authors: Simon Ser <<a href="mailto:simon.ser@intel.com" target="_blank">simon.ser@intel.com</a>><br>
*/<br>
<br>
+#ifdef __FreeBSD__<br>
+#include <limits.h><br>
+#endif<br>
+<br>
#include "config.h"<br>
<br>
#include <dirent.h><br>
diff --git a/lib/igt_frame.c b/lib/igt_frame.c<br>
index 45523a79..ab74e678 100644<br>
--- a/lib/igt_frame.c<br>
+++ b/lib/igt_frame.c<br>
@@ -24,6 +24,10 @@<br>
* Paul Kocialkowski <<a href="mailto:paul.kocialkowski@linux.intel.com" target="_blank">paul.kocialkowski@linux.intel.com</a>><br>
*/<br>
<br>
+#ifdef __FreeBSD__<br>
+#include <limits.h><br>
+#endif<br>
+<br>
#include "config.h"<br>
<br>
#include <fcntl.h><br>
diff --git a/lib/igt_kmod.c b/lib/igt_kmod.c<br>
index bcf7dfeb..12a22a95 100644<br>
--- a/lib/igt_kmod.c<br>
+++ b/lib/igt_kmod.c<br>
@@ -32,6 +32,7 @@<br>
#include "igt_sysfs.h"<br>
#include "igt_taints.h"<br>
<br>
+#ifdef __linux__<br>
/**<br>
* SECTION:igt_kmod<br>
* @short_description: Wrappers around libkmod for module loading/unloading<br>
@@ -853,3 +854,120 @@ void igt_kselftests(const char *module_name,<br>
<br>
igt_kselftest_fini(&tst);<br>
}<br>
+#elif defined(__FreeBSD__)<br>
+struct kmod_module {<br>
+ size_t size;<br>
+};<br>
+<br>
+bool<br>
+igt_kmod_is_loaded(const char *mod_name)<br>
+{<br>
+ return false;<br>
+}<br>
+<br>
+void<br>
+igt_kmod_list_loaded(void)<br>
+{<br>
+}<br>
+<br>
+bool<br>
+igt_kmod_has_param(const char *mod_name, const char *param)<br>
+{<br>
+ return false;<br>
+}<br>
+<br>
+int<br>
+igt_kmod_load(const char *mod_name, const char *opts)<br>
+{<br>
+ return -ENOSYS;<br>
+}<br>
+<br>
+int<br>
+igt_kmod_unload(const char *mod_name, unsigned int flags)<br>
+{<br>
+ return -ENOSYS;<br>
+}<br>
+<br>
+int<br>
+igt_audio_driver_unload(char **whom)<br>
+{<br>
+ return -ENOSYS;<br>
+}<br>
+<br>
+int<br>
+igt_i915_driver_load(const char *opts)<br>
+{<br>
+ return -ENOSYS;<br>
+}<br>
+<br>
+int<br>
+igt_i915_driver_unload(void)<br>
+{<br>
+ return -ENOSYS;<br>
+}<br>
+<br>
+int<br>
+__igt_i915_driver_unload(char **whom)<br>
+{<br>
+ return -ENOSYS;<br>
+}<br>
+<br>
+int<br>
+igt_amdgpu_driver_load(const char *opts)<br>
+{<br>
+ return -ENOSYS;<br>
+}<br>
+<br>
+int<br>
+igt_amdgpu_driver_unload(void)<br>
+{<br>
+ return -ENOSYS;<br>
+}<br>
+<br>
+void<br>
+igt_kselftests(const char *module_name,<br>
+ const char *module_options,<br>
+ const char *result_option,<br>
+ const char *filter)<br>
+{<br>
+}<br>
+<br>
+int<br>
+igt_kselftest_init(struct igt_kselftest *tst,<br>
+ const char *module_name)<br>
+{<br>
+ return -ENOSYS;<br>
+}<br>
+<br>
+int<br>
+igt_kselftest_begin(struct igt_kselftest *tst)<br>
+{<br>
+ return -ENOSYS;<br>
+}<br>
+<br>
+void<br>
+igt_kselftest_get_tests(struct kmod_module *kmod,<br>
+ const char *filter,<br>
+ struct igt_list_head *tests)<br>
+{<br>
+}<br>
+<br>
+int<br>
+igt_kselftest_execute(struct igt_kselftest *tst,<br>
+ struct igt_kselftest_list *tl,<br>
+ const char *module_options,<br>
+ const char *result)<br>
+{<br>
+ return -ENOSYS;<br>
+}<br>
+<br>
+void<br>
+igt_kselftest_end(struct igt_kselftest *tst)<br>
+{<br>
+}<br>
+<br>
+void<br>
+igt_kselftest_fini(struct igt_kselftest *tst)<br>
+{<br>
+}<br>
+#endif /* __linux__ */<br>
diff --git a/lib/igt_kmod.h b/lib/igt_kmod.h<br>
index f98dd29f..6596092b 100644<br>
--- a/lib/igt_kmod.h<br>
+++ b/lib/igt_kmod.h<br>
@@ -24,7 +24,9 @@<br>
#ifndef IGT_KMOD_H<br>
#define IGT_KMOD_H<br>
<br>
+#ifdef __linux__<br>
#include <libkmod.h><br>
+#endif<br>
<br>
#include "igt_list.h"<br>
<br>
diff --git a/lib/igt_kms.c b/lib/igt_kms.c<br>
index 1ba3bd2a..f0208c10 100644<br>
--- a/lib/igt_kms.c<br>
+++ b/lib/igt_kms.c<br>
@@ -43,6 +43,10 @@<br>
#include <sys/kd.h><br>
#endif<br>
<br>
+#ifdef __FreeBSD__<br>
+#include <sys/consio.h><br>
+#endif<br>
+<br>
#include <libudev.h><br>
#include <poll.h><br>
#include <errno.h><br>
diff --git a/lib/igt_os.c b/lib/igt_os.c<br>
index bdd5d933..ae426e3a 100644<br>
--- a/lib/igt_os.c<br>
+++ b/lib/igt_os.c<br>
@@ -44,6 +44,9 @@<br>
#include <sys/sysinfo.h><br>
#elif defined(HAVE_SWAPCTL) /* Solaris */<br>
#include <sys/swap.h><br>
+#elif defined(__FreeBSD__)<br>
+#include <sys/sysctl.h><br>
+#include <sys/types.h><br>
#endif<br>
#include <sys/resource.h><br>
<br>
@@ -148,6 +151,15 @@ igt_get_avail_ram_mb(void)<br>
npages = sysconf(_SC_AVPHYS_PAGES);<br>
<br>
retval = (uint64_t) pagesize * npages;<br>
+#elif defined(__FreeBSD__) /* FreeBSD */<br>
+ uint64_t npages, pagesize;<br>
+ size_t npages_len = sizeof(npages);<br>
+ size_t pagesize_len = sizeof(pagesize);<br>
+<br>
+ sysctlbyname("vm.stats.vm.v_free_count", &npages, &npages_len, NULL, 0);<br>
+ sysctlbyname("vm.stats.vm.v_page_size", &pagesize, &pagesize_len, NULL, 0);<br>
+<br>
+ retval = pagesize * npages;<br>
#else<br>
#error "Unknown how to get available RAM for this OS"<br>
#endif<br>
@@ -210,6 +222,13 @@ igt_get_total_swap_mb(void)<br>
free(buf);<br>
<br>
retval = (uint64_t) pagesize * totalpages;<br>
+#elif defined(__FreeBSD__) /* FreeBSD */<br>
+ uint64_t swap_total;<br>
+ size_t swap_total_len = sizeof(swap_total);<br>
+<br>
+ sysctlbyname("vm.swap_total", &swap_total, &swap_total_len, NULL, 0);<br>
+<br>
+ retval = swap_total;<br>
#else<br>
#warning "Unknown how to get swap size for this OS"<br>
return 0;<br>
diff --git a/lib/igt_perf.c b/lib/igt_perf.c<br>
index b743859f..90edbbd0 100644<br>
--- a/lib/igt_perf.c<br>
+++ b/lib/igt_perf.c<br>
@@ -4,13 +4,16 @@<br>
#include <stdlib.h><br>
#include <string.h><br>
#include <sys/stat.h><br>
+#ifdef __linux__<br>
#include <sys/sysinfo.h><br>
#include <sys/sysmacros.h><br>
+#endif<br>
#include <time.h><br>
#include <unistd.h><br>
<br>
#include "igt_perf.h"<br>
<br>
+#ifdef __linux__<br>
static char *bus_address(int i915, char *path, int pathlen)<br>
{<br>
struct stat st;<br>
@@ -157,3 +160,58 @@ int igt_perf_open_group(uint64_t type, uint64_t config, int group)<br>
return _perf_open(type, config, group,<br>
PERF_FORMAT_TOTAL_TIME_ENABLED | PERF_FORMAT_GROUP);<br>
}<br>
+#elif defined(__FreeBSD__)<br>
+uint64_t<br>
+igt_perf_type_id(const char *device)<br>
+{<br>
+ return -ENOSYS;<br>
+}<br>
+<br>
+int<br>
+igt_perf_open(uint64_t type, uint64_t config)<br>
+{<br>
+ return -ENOSYS;<br>
+}<br>
+<br>
+int<br>
+igt_perf_open_group(uint64_t type, uint64_t config, int group)<br>
+{<br>
+ return -ENOSYS;<br>
+}<br>
+<br>
+const char *<br>
+i915_perf_device(int i915, char *buf, int buflen)<br>
+{<br>
+ return strerror(ENOSYS);<br>
+}<br>
+<br>
+uint64_t<br>
+i915_perf_type_id(int i915)<br>
+{<br>
+ return -ENOSYS;<br>
+}<br>
+<br>
+int<br>
+perf_igfx_open(uint64_t config)<br>
+{<br>
+ return -ENOSYS;<br>
+}<br>
+<br>
+int<br>
+perf_igfx_open_group(uint64_t config, int group)<br>
+{<br>
+ return -ENOSYS;<br>
+}<br>
+<br>
+int<br>
+perf_i915_open(int i915, uint64_t config)<br>
+{<br>
+ return -ENOSYS;<br>
+}<br>
+<br>
+int<br>
+perf_i915_open_group(int i915, uint64_t config, int group)<br>
+{<br>
+ return -ENOSYS;<br>
+}<br>
+#endif /* __linux__ */<br>
diff --git a/lib/igt_perf.h b/lib/igt_perf.h<br>
index a8328c70..0cd91386 100644<br>
--- a/lib/igt_perf.h<br>
+++ b/lib/igt_perf.h<br>
@@ -27,10 +27,13 @@<br>
<br>
#include <stdint.h><br>
<br>
+#ifdef __linux__<br>
#include <linux/perf_event.h><br>
+#endif<br>
<br>
#include "igt_gt.h"<br>
<br>
+#ifdef __linux__<br>
static inline int<br>
perf_event_open(struct perf_event_attr *attr,<br>
pid_t pid,<br>
@@ -50,6 +53,7 @@ perf_event_open(struct perf_event_attr *attr,<br>
attr->size = sizeof(*attr);<br>
return syscall(__NR_perf_event_open, attr, pid, cpu, group_fd, flags);<br>
}<br>
+#endif /* __linux__ */<br>
<br>
uint64_t igt_perf_type_id(const char *device);<br>
int igt_perf_open(uint64_t type, uint64_t config);<br>
diff --git a/lib/igt_pm.c b/lib/igt_pm.c<br>
index 99251b40..a6036e03 100644<br>
--- a/lib/igt_pm.c<br>
+++ b/lib/igt_pm.c<br>
@@ -33,7 +33,9 @@<br>
#include <string.h><br>
#include <unistd.h><br>
#include <sys/stat.h><br>
+#ifdef __linux__<br>
#include <sys/sysmacros.h><br>
+#endif<br>
#include <sys/types.h><br>
#include <dirent.h><br>
<br>
diff --git a/lib/igt_syncobj.c b/lib/igt_syncobj.c<br>
index a24ed10b..eb302986 100644<br>
--- a/lib/igt_syncobj.c<br>
+++ b/lib/igt_syncobj.c<br>
@@ -27,6 +27,10 @@<br>
#include "igt.h"<br>
#include "igt_syncobj.h"<br>
<br>
+#ifdef __FreeBSD__<br>
+#define ETIME ETIMEDOUT<br>
+#endif<br>
+<br>
/**<br>
* SECTION:igt_syncobj<br>
* @short_description: Library with syncobj helpers<br>
diff --git a/lib/igt_sysfs.c b/lib/igt_sysfs.c<br>
index 9c307694..a913be4c 100644<br>
--- a/lib/igt_sysfs.c<br>
+++ b/lib/igt_sysfs.c<br>
@@ -24,7 +24,9 @@<br>
<br>
#include <inttypes.h><br>
#include <sys/stat.h><br>
+#ifdef __linux__<br>
#include <sys/sysmacros.h><br>
+#endif<br>
#include <sys/mount.h><br>
#include <errno.h><br>
#include <stdarg.h><br>
diff --git a/lib/igt_vgem.c b/lib/igt_vgem.c<br>
index 7f933b23..9483b896 100644<br>
--- a/lib/igt_vgem.c<br>
+++ b/lib/igt_vgem.c<br>
@@ -30,6 +30,11 @@<br>
#include "igt_core.h"<br>
#include "ioctl_wrappers.h"<br>
<br>
+#ifdef __FreeBSD__<br>
+#define mmap64(addr, len, prot, flags, fd, offset) \<br>
+ mmap(addr, len, prot, flags, fd, offset)<br>
+#endif<br>
+<br>
/**<br>
* SECTION:igt_vgem<br>
* @short_description: VGEM support library<br>
diff --git a/lib/intel_allocator.c b/lib/intel_allocator.c<br>
index 717d7fc5..bd840f57 100644<br>
--- a/lib/intel_allocator.c<br>
+++ b/lib/intel_allocator.c<br>
@@ -17,6 +17,10 @@<br>
#include "intel_allocator.h"<br>
#include "intel_allocator_msgchannel.h"<br>
<br>
+#ifdef __FreeBSD__<br>
+#define gettid() getpid()<br>
+#endif<br>
+<br>
//#define ALLOCDBG<br>
#ifdef ALLOCDBG<br>
#define alloc_info igt_info<br>
diff --git a/lib/intel_batchbuffer.c b/lib/intel_batchbuffer.c<br>
index ef1b5947..8004c09e 100644<br>
--- a/lib/intel_batchbuffer.c<br>
+++ b/lib/intel_batchbuffer.c<br>
@@ -60,6 +60,11 @@<br>
#define BCS_SRC_Y (1 << 0)<br>
#define BCS_DST_Y (1 << 1)<br>
<br>
+#ifdef __FreeBSD__<br>
+/* memory leak */<br>
+#define tdestroy(root, free_node)<br>
+#endif<br>
+<br>
/**<br>
* SECTION:intel_batchbuffer<br>
* @short_description: Batchbuffer and blitter support<br>
diff --git a/lib/sw_sync.c b/lib/sw_sync.c<br>
index 6c762c8b..e5a73ffa 100644<br>
--- a/lib/sw_sync.c<br>
+++ b/lib/sw_sync.c<br>
@@ -41,6 +41,10 @@<br>
#include "drmtest.h"<br>
#include "ioctl_wrappers.h"<br>
<br>
+#ifdef __FreeBSD__<br>
+#define ETIME ETIMEDOUT<br>
+#endif<br>
+<br>
/**<br>
* SECTION:sw_sync<br>
* @short_description: Software sync (fencing) support library<br>
diff --git a/lib/tests/igt_exit_handler.c b/lib/tests/igt_exit_handler.c<br>
index 892a7f14..d2381944 100644<br>
--- a/lib/tests/igt_exit_handler.c<br>
+++ b/lib/tests/igt_exit_handler.c<br>
@@ -125,5 +125,9 @@ int main(int argc, char **argv)<br>
internal_assert_wexited(status, IGT_EXIT_SKIP);<br>
<br>
status = testfunc(SIG);<br>
+#ifdef __linux__<br>
internal_assert_wsignaled(status, SIGTERM);<br>
+#elif defined(__FreeBSD__)<br>
+ internal_assert(status == 0);<br>
+#endif<br>
}<br>
diff --git a/lib/tests/igt_fork.c b/lib/tests/igt_fork.c<br>
index d19d0945..4a2d50d4 100644<br>
--- a/lib/tests/igt_fork.c<br>
+++ b/lib/tests/igt_fork.c<br>
@@ -109,7 +109,11 @@ __noreturn static void igt_fork_timeout_leak(void)<br>
__noreturn static void subtest_leak(void)<br>
{<br>
pid_t *children =<br>
+#ifdef __linux__<br>
mmap(0, 4096, PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0);<br>
+#elif defined(__FreeBSD__)<br>
+ mmap(0, 4096, PROT_WRITE | PROT_READ, MAP_SHARED | MAP_ANON, -1, 0);<br>
+#endif<br>
const int num_children = 4096 / sizeof(*children);<br>
<br>
igt_subtest_init(fake_argc, fake_argv);<br>
diff --git a/lib/tests/igt_tests_common.h b/lib/tests/igt_tests_common.h<br>
index 058f6265..e8183897 100644<br>
--- a/lib/tests/igt_tests_common.h<br>
+++ b/lib/tests/igt_tests_common.h<br>
@@ -48,8 +48,17 @@ static inline void internal_assert_wexited(int wstatus, int exitcode)<br>
<br>
static inline void internal_assert_wsignaled(int wstatus, int signal)<br>
{<br>
+#ifdef __linux__<br>
internal_assert(WIFSIGNALED(wstatus) &&<br>
WTERMSIG(wstatus) == signal);<br>
+#elif defined(__FreeBSD__)<br>
+ if (WIFSIGNALED(wstatus))<br>
+ internal_assert(WTERMSIG(wstatus) == signal);<br>
+ else if (WIFEXITED(wstatus))<br>
+ internal_assert(WEXITSTATUS(wstatus) == signal + 128);<br>
+ else<br>
+ internal_assert(0);<br>
+#endif<br>
}<br>
<br>
static inline void internal_assert_not_wsignaled(int wstatus)<br>
diff --git a/runner/executor.c b/runner/executor.c<br>
index 964d0063..65e3d2ba 100644<br>
--- a/runner/executor.c<br>
+++ b/runner/executor.c<br>
@@ -2,7 +2,9 @@<br>
#include <errno.h><br>
#include <fcntl.h><br>
#include <glib.h><br>
+#ifdef __linux__<br>
#include <linux/watchdog.h><br>
+#endif<br>
#if HAVE_OPING<br>
#include <oping.h><br>
#endif<br>
@@ -14,7 +16,9 @@<br>
#include <sys/ioctl.h><br>
#include <sys/select.h><br>
#include <sys/poll.h><br>
+#ifdef __linux__<br>
#include <sys/signalfd.h><br>
+#endif<br>
#include <sys/stat.h><br>
#include <sys/time.h><br>
#include <sys/types.h><br>
@@ -33,6 +37,16 @@<br>
#define KMSG_HEADER "[IGT] "<br>
#define KMSG_WARN 4<br>
<br>
+#ifdef __FreeBSD__<br>
+#include <sys/watchdog.h><br>
+struct signalfd_siginfo {<br>
+ uint32_t ssi_signo;<br>
+ uint32_t ssi_pid;<br>
+};<br>
+#define WDIOC_KEEPALIVE WDIOCPATPAT<br>
+#define signalfd(fd, mask, flags) -ENOSYS<br>
+#endif<br>
+<br>
static struct {<br>
int *fds;<br>
size_t num_dogs;<br>
diff --git a/tests/core_auth.c b/tests/core_auth.c<br>
index c9ad3fb9..fdd46e92 100644<br>
--- a/tests/core_auth.c<br>
+++ b/tests/core_auth.c<br>
@@ -48,6 +48,10 @@<br>
# include <pthread.h><br>
#endif<br>
<br>
+#ifdef __FreeBSD__<br>
+#define pthread_self() getpid()<br>
+#endif<br>
+<br>
IGT_TEST_DESCRIPTION("Call drmGetMagic() and drmAuthMagic() and see if it behaves.");<br>
<br>
static bool<br>
diff --git a/tests/drm_import_export.c b/tests/drm_import_export.c<br>
index 06245e8b..448d2d70 100644<br>
--- a/tests/drm_import_export.c<br>
+++ b/tests/drm_import_export.c<br>
@@ -45,6 +45,10 @@<br>
#define DURATION 10<br>
IGT_TEST_DESCRIPTION("Basic check to verify the behaviour of libdrm bo for prime/flink");<br>
<br>
+#ifdef __FreeBSD__<br>
+#define gettid() getpid()<br>
+#endif<br>
+<br>
int fd;<br>
drm_intel_bufmgr *bufmgr;<br>
int fd1;<br>
diff --git a/tests/dumb_buffer.c b/tests/dumb_buffer.c<br>
index 2c6261bd..e5278a90 100644<br>
--- a/tests/dumb_buffer.c<br>
+++ b/tests/dumb_buffer.c<br>
@@ -50,6 +50,11 @@<br>
#include "igt_aux.h"<br>
#include "ioctl_wrappers.h"<br>
<br>
+#ifdef __FreeBSD__<br>
+#undef jmp_buf<br>
+#define sighandler_t sig_t<br>
+#endif<br>
+<br>
IGT_TEST_DESCRIPTION("This is a test for the generic dumb buffer interface.");<br>
<br>
static int __dumb_create(int fd, struct drm_mode_create_dumb *create)<br>
diff --git a/tests/i915/gem_close_race.c b/tests/i915/gem_close_race.c<br>
index 938fde8f..0b7378b2 100644<br>
--- a/tests/i915/gem_close_race.c<br>
+++ b/tests/i915/gem_close_race.c<br>
@@ -53,6 +53,10 @@<br>
#define BLT_WRITE_ALPHA (1<<21)<br>
#define BLT_WRITE_RGB (1<<20)<br>
<br>
+#ifdef __FreeBSD__<br>
+#define gettid() getpid()<br>
+#endif<br>
+<br>
IGT_TEST_DESCRIPTION("Test try to race gem_close against workload submission.");<br>
<br>
static uint32_t devid;<br>
@@ -61,7 +65,9 @@ static bool has_softpin;<br>
static uint64_t exec_addr;<br>
static uint64_t data_addr;<br>
<br>
+#ifdef __linux__<br>
#define sigev_notify_thread_id _sigev_un._tid<br>
+#endif<br>
<br>
static void selfcopy(int fd, uint32_t ctx, uint32_t handle, int loops)<br>
{<br>
diff --git a/tests/i915/gem_concurrent_all.c b/tests/i915/gem_concurrent_all.c<br>
index 25b7daf8..e965dadb 100644<br>
--- a/tests/i915/gem_concurrent_all.c<br>
+++ b/tests/i915/gem_concurrent_all.c<br>
@@ -53,6 +53,11 @@<br>
#include "igt.h"<br>
#include "igt_vgem.h"<br>
<br>
+/* improper substitution */<br>
+#ifdef __FreeBSD__<br>
+#define MADV_DONTFORK MADV_NOSYNC<br>
+#endif<br>
+<br>
IGT_TEST_DESCRIPTION("Test of pread/pwrite/mmap behavior when writing to active"<br>
" buffers.");<br>
<br>
diff --git a/tests/i915/gem_create.c b/tests/i915/gem_create.c<br>
index d7d2a017..18d9324e 100644<br>
--- a/tests/i915/gem_create.c<br>
+++ b/tests/i915/gem_create.c<br>
@@ -61,6 +61,10 @@<br>
#include "i915/gem_mman.h"<br>
#include "i915_drm.h"<br>
<br>
+#ifdef __FreeBSD__<br>
+#define sighandler_t sig_t<br>
+#endif<br>
+<br>
IGT_TEST_DESCRIPTION("Ensure that basic gem_create and gem_create_ext works"<br>
" and that invalid input combinations are rejected.");<br>
<br>
diff --git a/tests/i915/gem_ctx_exec.c b/tests/i915/gem_ctx_exec.c<br>
index 3d94f01d..3cc7a87c 100644<br>
--- a/tests/i915/gem_ctx_exec.c<br>
+++ b/tests/i915/gem_ctx_exec.c<br>
@@ -48,6 +48,10 @@<br>
#include "igt_sysfs.h"<br>
#include "sw_sync.h"<br>
<br>
+#ifdef __FreeBSD__<br>
+#define ETIME ETIMEDOUT<br>
+#endif<br>
+<br>
IGT_TEST_DESCRIPTION("Test context batch buffer execution.");<br>
<br>
/* Copied from gem_exec_nop.c */<br>
diff --git a/tests/i915/gem_ctx_persistence.c b/tests/i915/gem_ctx_persistence.c<br>
index 50196edb..afda4675 100644<br>
--- a/tests/i915/gem_ctx_persistence.c<br>
+++ b/tests/i915/gem_ctx_persistence.c<br>
@@ -50,6 +50,10 @@<br>
static unsigned long reset_timeout_ms = RESET_TIMEOUT_MS;<br>
#define NSEC_PER_MSEC (1000 * 1000ull)<br>
<br>
+#ifdef __FreeBSD__<br>
+#define ETIME ETIMEDOUT<br>
+#endif<br>
+<br>
static void cleanup(int i915)<br>
{<br>
igt_drop_caches_set(i915,<br>
diff --git a/tests/i915/gem_ctx_shared.c b/tests/i915/gem_ctx_shared.c<br>
index eb3b024f..fe1c788b 100644<br>
--- a/tests/i915/gem_ctx_shared.c<br>
+++ b/tests/i915/gem_ctx_shared.c<br>
@@ -54,6 +54,10 @@<br>
#define MAX_PRIO I915_CONTEXT_MAX_USER_PRIORITY<br>
#define MIN_PRIO I915_CONTEXT_MIN_USER_PRIORITY<br>
<br>
+#ifdef __FreeBSD__<br>
+#define ETIME ETIMEDOUT<br>
+#endif<br>
+<br>
static int priorities[] = {<br>
[LO] = MIN_PRIO / 2,<br>
[HI] = MAX_PRIO / 2,<br>
diff --git a/tests/i915/gem_exec_fence.c b/tests/i915/gem_exec_fence.c<br>
index f24bebdb..50b14c87 100644<br>
--- a/tests/i915/gem_exec_fence.c<br>
+++ b/tests/i915/gem_exec_fence.c<br>
@@ -36,6 +36,10 @@<br>
#include "intel_ctx.h"<br>
#include "sw_sync.h"<br>
<br>
+#ifdef __FreeBSD__<br>
+#define ETIME ETIMEDOUT<br>
+#endif<br>
+<br>
IGT_TEST_DESCRIPTION("Check that execbuf waits for explicit fences");<br>
<br>
#ifndef SYNC_IOC_MERGE<br>
diff --git a/tests/i915/gem_exec_latency.c b/tests/i915/gem_exec_latency.c<br>
index fcdf7787..dad9ea27 100644<br>
--- a/tests/i915/gem_exec_latency.c<br>
+++ b/tests/i915/gem_exec_latency.c<br>
@@ -55,6 +55,10 @@<br>
#define CORK 0x2<br>
#define PREEMPT 0x4<br>
<br>
+#ifdef __FreeBSD__<br>
+#define SCHED_RESET_ON_FORK 0<br>
+#endif<br>
+<br>
static unsigned int ring_size;<br>
static double rcs_clock;<br>
static struct intel_mmio_data mmio_data;<br>
diff --git a/tests/i915/gem_lmem_swapping.c b/tests/i915/gem_lmem_swapping.c<br>
index cccdb319..34ca455f 100644<br>
--- a/tests/i915/gem_lmem_swapping.c<br>
+++ b/tests/i915/gem_lmem_swapping.c<br>
@@ -25,6 +25,10 @@<br>
#include "i915/i915_blt.h"<br>
#include "i915/intel_mocs.h"<br>
<br>
+#ifdef __FreeBSD__<br>
+#define MAP_POPULATE MAP_PREFAULT_READ<br>
+#endif<br>
+<br>
IGT_TEST_DESCRIPTION("Exercise local memory swapping.");<br>
<br>
#define __round_mask(x, y) ((__typeof__(x))((y) - 1))<br>
diff --git a/tests/i915/gem_madvise.c b/tests/i915/gem_madvise.c<br>
index 2502d84c..4c6cdbc4 100644<br>
--- a/tests/i915/gem_madvise.c<br>
+++ b/tests/i915/gem_madvise.c<br>
@@ -39,6 +39,10 @@<br>
#include "drm.h"<br>
#include "i915/gem_create.h"<br>
<br>
+#ifdef __FreeBSD__<br>
+#define sighandler_t sig_t<br>
+#endif<br>
+<br>
IGT_TEST_DESCRIPTION("Checks that the kernel reports EFAULT when trying to use"<br>
" purged bo.");<br>
<br>
diff --git a/tests/i915/gem_mmap_gtt.c b/tests/i915/gem_mmap_gtt.c<br>
index e39b9047..8daa6248 100644<br>
--- a/tests/i915/gem_mmap_gtt.c<br>
+++ b/tests/i915/gem_mmap_gtt.c<br>
@@ -54,6 +54,16 @@<br>
<br>
#define abs(x) ((x) >= 0 ? (x) : -(x))<br>
<br>
+#ifdef __FreeBSD__<br>
+#define mmap64(addr, len, prot, flags, fd, offset) \<br>
+ mmap(addr, len, prot, flags, fd, offset)<br>
+#define PTRACE_TRACEME PT_TRACE_ME<br>
+#define PTRACE_ATTACH PT_ATTACH<br>
+#define PTRACE_PEEKDATA PT_READ_D<br>
+#define PTRACE_POKEDATA PT_WRITE_D<br>
+#define PTRACE_DETACH PT_DETACH<br>
+#endif<br>
+<br>
IGT_TEST_DESCRIPTION("Ensure that all operations around MMAP_GTT ioctl works.");<br>
<br>
static int OBJECT_SIZE = 16*1024*1024;<br>
@@ -566,7 +576,11 @@ test_ptrace(int fd)<br>
for (int i = 0; i < sz / sizeof(long); i++) {<br>
long ret;<br>
<br>
+#ifdef __linux__<br>
ret = ptrace(PTRACE_PEEKDATA, pid, gtt + i);<br>
+#elif defined(__FreeBSD__)<br>
+ ret = ptrace(PTRACE_PEEKDATA, pid, gtt + i, 0);<br>
+#endif<br>
igt_assert_eq_u64(ret, CC);<br>
cpy[i] = ret;<br>
<br>
diff --git a/tests/i915/gem_mmap_offset.c b/tests/i915/gem_mmap_offset.c<br>
index 5e6b19eb..21bcdddd 100644<br>
--- a/tests/i915/gem_mmap_offset.c<br>
+++ b/tests/i915/gem_mmap_offset.c<br>
@@ -38,6 +38,16 @@<br>
#include "igt.h"<br>
#include "igt_x86.h"<br>
<br>
+#ifdef __FreeBSD__<br>
+#define mmap64(addr, len, prot, flags, fd, offset) \<br>
+ mmap(addr, len, prot, flags, fd, offset)<br>
+#define PTRACE_TRACEME PT_TRACE_ME<br>
+#define PTRACE_ATTACH PT_ATTACH<br>
+#define PTRACE_PEEKDATA PT_READ_D<br>
+#define PTRACE_POKEDATA PT_WRITE_D<br>
+#define PTRACE_DETACH PT_DETACH<br>
+#endif<br>
+<br>
IGT_TEST_DESCRIPTION("Basic MMAP_OFFSET IOCTL tests for mem regions\n");<br>
<br>
static int mmap_offset_ioctl(int i915, struct drm_i915_gem_mmap_offset *arg)<br>
@@ -370,7 +380,11 @@ static void test_ptrace(int i915)<br>
for (int i = 0; i < SZ / sizeof(long); i++) {<br>
long ret;<br>
<br>
+#ifdef __linux__<br>
ret = ptrace(PTRACE_PEEKDATA, pid, ptr + i);<br>
+#elif defined(__FreeBSD__)<br>
+ ret = ptrace(PTRACE_PEEKDATA, pid, ptr + i, 0);<br>
+#endif<br>
igt_assert_eq_u64(ret, CC);<br>
cpy[i] = ret;<br>
<br>
diff --git a/tests/i915/gem_shrink.c b/tests/i915/gem_shrink.c<br>
index 49df35c2..e9dd49cf 100644<br>
--- a/tests/i915/gem_shrink.c<br>
+++ b/tests/i915/gem_shrink.c<br>
@@ -38,6 +38,10 @@<br>
#define MADV_FREE 8<br>
#endif<br>
<br>
+#ifdef __FreeBSD__<br>
+#define MAP_POPULATE MAP_PREFAULT_READ<br>
+#endif<br>
+<br>
static void get_pages(int fd, uint64_t alloc)<br>
{<br>
uint32_t handle = gem_create(fd, alloc);<br>
diff --git a/tests/i915/gem_wait.c b/tests/i915/gem_wait.c<br>
index 230304aa..9655fb09 100644<br>
--- a/tests/i915/gem_wait.c<br>
+++ b/tests/i915/gem_wait.c<br>
@@ -32,6 +32,10 @@<br>
#include "igt.h"<br>
#include "igt_vgem.h"<br>
<br>
+#ifdef __FreeBSD__<br>
+#define ETIME ETIMEDOUT<br>
+#endif<br>
+<br>
IGT_TEST_DESCRIPTION("Tests the GEM_WAIT ioctl");<br>
<br>
static int __gem_wait(int fd, struct drm_i915_gem_wait *w)<br>
diff --git a/tests/i915/i915_hangman.c b/tests/i915/i915_hangman.c<br>
index c7d69fdd..c0bde6be 100644<br>
--- a/tests/i915/i915_hangman.c<br>
+++ b/tests/i915/i915_hangman.c<br>
@@ -50,6 +50,10 @@ static int sysfs = -1;<br>
<br>
#define OFFSET_ALIVE 10<br>
<br>
+#ifdef __FreeBSD__<br>
+#define ETIME ETIMEDOUT<br>
+#endif<br>
+<br>
IGT_TEST_DESCRIPTION("Tests for hang detection and recovery");<br>
<br>
static void check_alive(void)<br>
diff --git a/tests/i915/i915_module_load.c b/tests/i915/i915_module_load.c<br>
index 4c72157c..9bec4c18 100644<br>
--- a/tests/i915/i915_module_load.c<br>
+++ b/tests/i915/i915_module_load.c<br>
@@ -23,7 +23,9 @@<br>
#include "igt.h"<br>
#include <dirent.h><br>
#include <sys/utsname.h><br>
+#ifdef __linux__<br>
#include <linux/limits.h><br>
+#endif<br>
#include <signal.h><br>
#include <libgen.h><br>
#include <signal.h><br>
diff --git a/tests/i915/i915_pm_backlight.c b/tests/i915/i915_pm_backlight.c<br>
index cafae7f7..c520cf20 100644<br>
--- a/tests/i915/i915_pm_backlight.c<br>
+++ b/tests/i915/i915_pm_backlight.c<br>
@@ -46,6 +46,10 @@ struct context {<br>
#define FADESTEPS 10<br>
#define FADESPEED 100 /* milliseconds between steps */<br>
<br>
+#ifdef __FreeBSD__<br>
+#include <libgen.h><br>
+#endif<br>
+<br>
IGT_TEST_DESCRIPTION("Basic backlight sysfs test");<br>
<br>
static int backlight_read(int *result, const char *fname)<br>
diff --git a/tests/i915/i915_pm_rpm.c b/tests/i915/i915_pm_rpm.c<br>
index e95875dc..6a30ecf6 100644<br>
--- a/tests/i915/i915_pm_rpm.c<br>
+++ b/tests/i915/i915_pm_rpm.c<br>
@@ -40,8 +40,10 @@<br>
#include <sys/mman.h><br>
#include <sys/types.h><br>
#include <sys/stat.h><br>
+#ifdef __linux__<br>
#include <linux/i2c.h><br>
#include <linux/i2c-dev.h><br>
+#endif<br>
<br>
#include <drm.h><br>
<br>
@@ -54,6 +56,17 @@<br>
#include "igt_device.h"<br>
#include "igt_edid.h"<br>
<br>
+#ifdef __FreeBSD__<br>
+#include <limits.h><br>
+#include <dev/iicbus/iic.h><br>
+<br>
+#define I2C_RDWR I2CRDWR<br>
+#define I2C_M_RD IIC_M_RD<br>
+#define i2c_msg iic_msg<br>
+#define i2c_rdwr_ioctl_data iic_rdwr_data<br>
+#define addr slave<br>
+#endif<br>
+<br>
#define MSR_PC8_RES 0x630<br>
#define MSR_PC9_RES 0x631<br>
#define MSR_PC10_RES 0x632<br>
diff --git a/tests/i915/sysfs_heartbeat_interval.c b/tests/i915/sysfs_heartbeat_interval.c<br>
index 8cebf627..cb1f37f8 100644<br>
--- a/tests/i915/sysfs_heartbeat_interval.c<br>
+++ b/tests/i915/sysfs_heartbeat_interval.c<br>
@@ -42,6 +42,10 @@<br>
#include "igt_sysfs.h"<br>
#include "sw_sync.h"<br>
<br>
+#ifdef __FreeBSD__<br>
+#define sighandler_t sig_t<br>
+#endif<br>
+<br>
#define ATTR "heartbeat_interval_ms"<br>
#define RESET_TIMEOUT 50 /* milliseconds, at least one jiffie for kworker */<br>
<br>
diff --git a/tests/kms_content_protection.c b/tests/kms_content_protection.c<br>
index 3041f1cd..e0e5af78 100644<br>
--- a/tests/kms_content_protection.c<br>
+++ b/tests/kms_content_protection.c<br>
@@ -24,7 +24,9 @@<br>
<br>
#include <poll.h><br>
#include <fcntl.h><br>
+#ifdef __linux__<br>
#include <sys/epoll.h><br>
+#endif<br>
#include <sys/stat.h><br>
#include <libudev.h><br>
#include "igt.h"<br>
diff --git a/tests/kms_cursor_legacy.c b/tests/kms_cursor_legacy.c<br>
index 1b697667..67a470b6 100644<br>
--- a/tests/kms_cursor_legacy.c<br>
+++ b/tests/kms_cursor_legacy.c<br>
@@ -47,6 +47,10 @@<br>
<br>
#define PAGE_SIZE 4096<br>
<br>
+#ifdef __FreeBSD__<br>
+#define SCHED_IDLE SCHED_OTHER<br>
+#endif<br>
+<br>
IGT_TEST_DESCRIPTION("Stress legacy cursor ioctl");<br>
<br>
igt_pipe_crc_t *pipe_crc;<br>
diff --git a/tests/kms_flip.c b/tests/kms_flip.c<br>
index 0567edea..1127e418 100755<br>
--- a/tests/kms_flip.c<br>
+++ b/tests/kms_flip.c<br>
@@ -45,6 +45,10 @@<br>
#include "i915/gem_create.h"<br>
#include "igt_stats.h"<br>
<br>
+#ifdef __FreeBSD__<br>
+#include <sys/consio.h><br>
+#endif<br>
+<br>
#define TEST_DPMS (1 << 0)<br>
<br>
#define TEST_PAN (1 << 3)<br>
diff --git a/tests/kms_sysfs_edid_timing.c b/tests/kms_sysfs_edid_timing.c<br>
index 77521108..cd980c6a 100644<br>
--- a/tests/kms_sysfs_edid_timing.c<br>
+++ b/tests/kms_sysfs_edid_timing.c<br>
@@ -26,6 +26,10 @@<br>
#include <fcntl.h><br>
#include <sys/stat.h><br>
<br>
+#ifdef __FreeBSD__<br>
+#include <limits.h><br>
+#endif<br>
+<br>
#define THRESHOLD_PER_CONNECTOR 150<br>
#define THRESHOLD_PER_CONNECTOR_MEAN 140<br>
#define THRESHOLD_ALL_CONNECTORS_MEAN 100<br>
diff --git a/tests/sw_sync.c b/tests/sw_sync.c<br>
index cbd773fc..1290a284 100644<br>
--- a/tests/sw_sync.c<br>
+++ b/tests/sw_sync.c<br>
@@ -38,6 +38,9 @@<br>
<br>
#include "sw_sync.h"<br>
<br>
+#ifdef __FreeBSD__<br>
+#define ETIME ETIMEDOUT<br>
+#endif<br>
<br>
IGT_TEST_DESCRIPTION("Test SW Sync Framework");<br>
<br>
diff --git a/tests/syncobj_timeline.c b/tests/syncobj_timeline.c<br>
index 20375cdd..795fd3fb 100644<br>
--- a/tests/syncobj_timeline.c<br>
+++ b/tests/syncobj_timeline.c<br>
@@ -31,6 +31,10 @@<br>
#include <signal.h><br>
#include "drm.h"<br>
<br>
+#ifdef __FreeBSD__<br>
+#define ETIME ETIMEDOUT<br>
+#endif<br>
+<br>
IGT_TEST_DESCRIPTION("Tests for the drm timeline sync object API");<br>
<br>
/* One tenth of a second */<br>
diff --git a/tests/syncobj_wait.c b/tests/syncobj_wait.c<br>
index 669d0adf..4f31fb76 100644<br>
--- a/tests/syncobj_wait.c<br>
+++ b/tests/syncobj_wait.c<br>
@@ -31,6 +31,10 @@<br>
#include <signal.h><br>
#include "drm.h"<br>
<br>
+#ifdef __FreeBSD__<br>
+#define ETIME ETIMEDOUT<br>
+#endif<br>
+<br>
IGT_TEST_DESCRIPTION("Tests for the drm sync object wait API");<br>
<br>
/* One tenth of a second */<br>
diff --git a/tests/tools_test.c b/tests/tools_test.c<br>
index 237f0433..6652927a 100644<br>
--- a/tests/tools_test.c<br>
+++ b/tests/tools_test.c<br>
@@ -28,7 +28,12 @@<br>
#include <fcntl.h><br>
#include <libgen.h><br>
#include <unistd.h><br>
+#ifdef __linux__<br>
#include <linux/limits.h><br>
+#elif defined(__FreeBSD__)<br>
+#include <limits.h><br>
+#define get_current_dir_name() getwd(NULL)<br>
+#endif<br>
<br>
#define TOOLS "../tools/"<br>
<br>
diff --git a/tests/vc4_purgeable_bo.c b/tests/vc4_purgeable_bo.c<br>
index d9f7547f..5aa734b4 100644<br>
--- a/tests/vc4_purgeable_bo.c<br>
+++ b/tests/vc4_purgeable_bo.c<br>
@@ -35,6 +35,10 @@<br>
#include <sys/ioctl.h><br>
#include "vc4_drm.h"<br>
<br>
+#ifdef __FreeBSD__<br>
+#undef jmp_buf<br>
+#endif<br>
+<br>
struct igt_vc4_bo {<br>
struct igt_list_head node;<br>
int handle;<br>
diff --git a/tests/vc4_wait_bo.c b/tests/vc4_wait_bo.c<br>
index 65a085a3..2c3c9da8 100644<br>
--- a/tests/vc4_wait_bo.c<br>
+++ b/tests/vc4_wait_bo.c<br>
@@ -34,6 +34,10 @@<br>
#include <sys/ioctl.h><br>
#include "vc4_drm.h"<br>
<br>
+#ifdef __FreeBSD__<br>
+#define ETIME ETIMEDOUT<br>
+#endif<br>
+<br>
static void<br>
test_used_bo(int fd, uint64_t timeout)<br>
{<br>
diff --git a/tests/vc4_wait_seqno.c b/tests/vc4_wait_seqno.c<br>
index bcc263cb..c04c8d78 100644<br>
--- a/tests/vc4_wait_seqno.c<br>
+++ b/tests/vc4_wait_seqno.c<br>
@@ -33,6 +33,10 @@<br>
#include <sys/ioctl.h><br>
#include "vc4_drm.h"<br>
<br>
+#ifdef __FreeBSD__<br>
+#define ETIME ETIMEDOUT<br>
+#endif<br>
+<br>
igt_main<br>
{<br>
int fd;<br>
diff --git a/tools/intel_gvtg_test.c b/tools/intel_gvtg_test.c<br>
index ad5ee6a6..2f0c94f0 100644<br>
--- a/tools/intel_gvtg_test.c<br>
+++ b/tools/intel_gvtg_test.c<br>
@@ -44,6 +44,9 @@<br>
#include <sys/ioctl.h><br>
#include <sys/types.h><br>
#include <sys/stat.h><br>
+#ifdef __FreeBSD__<br>
+#include <sys/wait.h><br>
+#endif<br>
#include <string.h><br>
#include <stdlib.h><br>
#include <signal.h><br>
-- <br>
2.37.2<br>
<br>
</blockquote></div>