@@ -51,12 +51,22 @@ int setup_listening_socket(int port, int ipv6)
if (ret < 0) {
perror("bind()");
return -1;
}
if (listen(fd, 1024) < 0) {
perror("listen()");
return -1;
}
return fd;
}
+
+void *aligned_alloc(size_t alignment, size_t size)
+{
+ void *ret;
+
+ if (posix_memalign(&ret, alignment, size))
+ return NULL;
+
+ return ret;
+}
@@ -1,7 +1,14 @@
/* SPDX-License-Identifier: MIT */
#ifndef LIBURING_EX_HELPERS_H
#define LIBURING_EX_HELPERS_H
int setup_listening_socket(int port, int ipv6);
+/*
+ * Some Android versions lack aligned_alloc in stdlib.h.
+ * To avoid making large changes in tests, define a helper
+ * function that wraps posix_memalign as our own aligned_alloc.
+ */
+void *aligned_alloc(size_t alignment, size_t size);
+
#endif
@@ -4,24 +4,26 @@
*
* (C) 2024 Jens Axboe <axboe@kernel.dk>
*/
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <assert.h>
#include <sys/time.h>
#include <liburing.h>
+#include "helpers.h"
+
static unsigned long long mtime_since(const struct timeval *s,
const struct timeval *e)
{
long long sec, usec;
sec = e->tv_sec - s->tv_sec;
usec = (e->tv_usec - s->tv_usec);
if (sec > 0 && usec < 0) {
sec--;
usec += 1000000;
}
@@ -354,12 +354,22 @@ unsigned long long utime_since(const struct timeval *s, const struct timeval *e)
sec *= 1000000;
return sec + usec;
}
unsigned long long utime_since_now(struct timeval *tv)
{
struct timeval end;
gettimeofday(&end, NULL);
return utime_since(tv, &end);
}
+
+void *aligned_alloc(size_t alignment, size_t size)
+{
+ void *ret;
+
+ if (posix_memalign(&ret, alignment, size))
+ return NULL;
+
+ return ret;
+}
@@ -4,36 +4,44 @@
*/
#ifndef LIBURING_HELPERS_H
#define LIBURING_HELPERS_H
#ifdef __cplusplus
extern "C" {
#endif
#include "liburing.h"
#include "../src/setup.h"
#include <arpa/inet.h>
#include <sys/time.h>
+#include <stdlib.h>
enum t_setup_ret {
T_SETUP_OK = 0,
T_SETUP_SKIP,
};
enum t_test_result {
T_EXIT_PASS = 0,
T_EXIT_FAIL = 1,
T_EXIT_SKIP = 77,
};
+/*
+ * Some Android versions lack aligned_alloc in stdlib.h.
+ * To avoid making large changes in tests, define a helper
+ * function that wraps posix_memalign as our own aligned_alloc.
+ */
+void *aligned_alloc(size_t alignment, size_t size);
+
/*
* Helper for binding socket to an ephemeral port.
* The port number to be bound is returned in @addr->sin_port.
*/
int t_bind_ephemeral_port(int fd, struct sockaddr_in *addr);
/*
* Helper for allocating memory in tests.
*/
void *t_malloc(size_t size);