From 980d30092b09a1f8083e83da03c441abd027128d Mon Sep 17 00:00:00 2001
From: GeorgyKirichenko <kirichenkoga@gmail.com>
Date: Thu, 25 May 2017 17:26:13 +0300
Subject: [PATCH] Fix test/unit/fiber.test

* Disable code optimization for fiber unit test
* Get rid of abs() usge

Follow up #2438
---
 test/unit/CMakeLists.txt |  1 +
 test/unit/fiber.cc       | 10 ++++++----
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt
index 39363cc06d..bdbdf4dd6a 100644
--- a/test/unit/CMakeLists.txt
+++ b/test/unit/CMakeLists.txt
@@ -68,6 +68,7 @@ add_executable(xrow.test xrow.cc unit.c
 target_link_libraries(xrow.test server misc ${MSGPUCK_LIBRARIES})
 
 add_executable(fiber.test fiber.cc unit.c)
+set_source_files_properties(fiber.cc PROPERTIES COMPILE_FLAGS -O0)
 target_link_libraries(fiber.test core)
 
 if (NOT ENABLE_GCOV)
diff --git a/test/unit/fiber.cc b/test/unit/fiber.cc
index eee80df6ce..2e75e58337 100644
--- a/test/unit/fiber.cc
+++ b/test/unit/fiber.cc
@@ -1,6 +1,7 @@
 #include "memory.h"
 #include "fiber.h"
 #include "unit.h"
+#include "trivia/util.h"
 
 static int
 noop_f(va_list ap)
@@ -48,13 +49,14 @@ cancel_dead_f(va_list ap)
 
 static size_t fiber_stack_size_default;
 
-static void
+static void NOINLINE
 stack_expand(void *ptr)
 {
 	char buf[2048];
-	memset(buf, 0, 2048);
-	long int stack_diff = (long int)(buf - (char *)ptr);
-	if (abs(stack_diff) < (long int)fiber_stack_size_default)
+	memset(buf, 0x45, 2048);
+	ptrdiff_t stack_diff = (buf - (char *)ptr);
+	stack_diff = stack_diff >= 0 ? stack_diff : -stack_diff;
+	if (stack_diff < (ptrdiff_t)fiber_stack_size_default)
 		stack_expand(ptr);
 }
 
-- 
GitLab