Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
108 commits
Select commit Hold shift + click to select a range
7ac44ab
change mac os version
andarut May 16, 2023
9ecc823
test without ASAN
andarut May 19, 2023
b42c5e9
test
andarut May 19, 2023
a454320
test
andarut May 19, 2023
f40be93
test
andarut May 19, 2023
2ac5d0f
test
andarut May 19, 2023
1ce4673
test
andarut May 19, 2023
294950f
test
andarut May 19, 2023
d981c24
test
andarut May 19, 2023
133b4d4
test
andarut May 19, 2023
986e876
test
andarut May 19, 2023
95c470b
test
andarut May 19, 2023
e3fa5db
test
andarut May 19, 2023
b5bd9fe
test
andarut May 20, 2023
f7c24c2
test
andarut May 20, 2023
1b46010
test
andarut May 20, 2023
6ecd2ef
test
andarut May 20, 2023
33b2041
test
andarut May 20, 2023
90549ad
test
andarut May 20, 2023
3912434
test
andarut May 20, 2023
624a0ad
test
andarut May 20, 2023
59d21a1
test
andarut May 21, 2023
1a76a5e
test
andarut May 21, 2023
6844c8c
test
andarut May 21, 2023
8c62501
test
andarut May 21, 2023
a823597
test
andarut May 21, 2023
a26a30f
test
andarut May 21, 2023
3ecddf0
test
andarut May 21, 2023
6ed4024
test
andarut May 21, 2023
43bbe47
test
andarut May 21, 2023
899995c
test
andarut May 21, 2023
c36839a
test
andarut May 21, 2023
02fe56d
test
andarut May 21, 2023
fde96e8
test
andarut May 21, 2023
a054f0b
test
andarut May 21, 2023
561da58
test
andarut May 21, 2023
ef96a49
test
andarut May 21, 2023
4dd7aa1
test
andarut May 21, 2023
dcf917c
test
andarut May 21, 2023
ca2f66c
test
andarut May 21, 2023
9ba328c
test
andarut May 21, 2023
2334931
test
andarut May 21, 2023
7bd33cd
test
andarut May 21, 2023
bbf549b
test
andarut May 21, 2023
e2f57a4
test
andarut May 21, 2023
47c18de
test
andarut May 21, 2023
9069b88
test
andarut May 21, 2023
3fb86c7
test
andarut May 21, 2023
c2d5726
test
andarut May 21, 2023
00f6fda
test
andarut May 21, 2023
ca84f9c
test
andarut May 21, 2023
1d84d66
test
andarut May 21, 2023
6fdddce
test 1
andarut May 21, 2023
c70eb31
test 1
andarut May 21, 2023
33a99ea
test 3
andarut May 21, 2023
fc8cf3c
test 4
andarut May 21, 2023
699c0e9
test 5
andarut May 21, 2023
08952dc
test 5
andarut May 21, 2023
67d899c
test 6
andarut May 21, 2023
411d5bc
test 7
andarut May 21, 2023
39e4c57
test 8
andarut May 21, 2023
2993707
test 9
andarut May 21, 2023
0c9b9ce
test 10
andarut May 22, 2023
05dee49
test 10
andarut May 22, 2023
62b2f29
test 10
andarut May 22, 2023
3f734ce
test 11
andarut May 22, 2023
319aa6b
test 12
andarut May 22, 2023
5166913
test 13
andarut May 22, 2023
2f0ff5b
test 13
andarut May 22, 2023
fbf788f
test 13
andarut May 22, 2023
49ef186
test 14
andarut May 22, 2023
f78f4bf
test 14
andarut May 22, 2023
e2e377e
test 14
andarut May 22, 2023
4b55b78
test 15
andarut May 22, 2023
8607095
test 16
andarut May 22, 2023
dbdd917
test 158
andarut May 23, 2023
2657a32
fix
andarut May 23, 2023
08fb285
test 160
andarut May 23, 2023
cb3bb8b
test 161
andarut May 23, 2023
5ad2f5a
final soon
andarut May 23, 2023
dee1641
test
andarut May 23, 2023
f417b0b
test
andarut May 23, 2023
a5bdfda
test 189
andarut May 23, 2023
8382798
maybe
andarut May 23, 2023
0684b8a
maybe
andarut May 23, 2023
216ef5d
another test
andarut May 23, 2023
47cfa38
another test
andarut May 24, 2023
4317844
try fix test 1
andarut May 24, 2023
c34bee0
test
andarut May 24, 2023
9d17e91
test
andarut May 24, 2023
219c20e
test
andarut May 24, 2023
3b6b7cc
test
andarut May 24, 2023
3cb756e
test
andarut May 24, 2023
9b86286
test
andarut May 24, 2023
3b1bf16
test
andarut May 24, 2023
0ed001c
test
andarut May 24, 2023
78b1fb0
test with rewrite code
andarut May 24, 2023
ee4f485
test
andarut May 24, 2023
27e44e3
test
andarut May 24, 2023
49d1140
test
andarut May 24, 2023
74bf13f
test
andarut May 24, 2023
dbc63ac
test
andarut May 24, 2023
860fb24
test
andarut May 24, 2023
69834c7
test
andarut May 24, 2023
a21a5ff
test
andarut May 24, 2023
f15c425
test
andarut May 24, 2023
77574d3
test
andarut May 24, 2023
39982ab
test
andarut May 24, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/Build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ jobs:
- os: focal
compiler: g++-10
cpp: 20
asan: on
asan: off
ubsan: off
- os: jammy
compiler: g++
cpp: 20
asan: on
asan: off
ubsan: off

name: "${{matrix.os}}/${{matrix.compiler}}/c++${{matrix.cpp}}/asan=${{matrix.asan}}/ubsan=${{matrix.ubsan}}"
Expand Down Expand Up @@ -161,4 +161,4 @@ jobs:
run: |
echo 'hello world' > demo.php
$GITHUB_WORKSPACE/objs/bin/kphp2cpp --cxx ${{matrix.compiler}} demo.php
kphp_out/server -o
kphp_out/server -o
2 changes: 1 addition & 1 deletion .github/workflows/Dockerfile.buster
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ RUN apt-get update && \
apt-get install -y --no-install-recommends curl-kphp-vk kphp-timelib libuber-h3-dev libfmt-dev libgtest-dev libgmock-dev libre2-dev libpcre3-dev \
libzstd-dev libyaml-cpp-dev libnghttp2-dev zlib1g-dev php7.4-dev mysql-server libmysqlclient-dev libldap-dev libkrb5-dev \
postgresql postgresql-server-dev-all libnuma-dev composer && \
pip3 install portalocker psutil requests-toolbelt pytest pytest-xdist pytest-mysql pytest-postgresql psycopg zstandard && \
pip3 install portalocker psutil urllib3 requests-toolbelt pytest pytest-xdist pytest-mysql pytest-postgresql psycopg zstandard && \
rm -rf /var/lib/apt/lists/* && \
update-alternatives --set php /usr/bin/php7.4

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/Dockerfile.focal
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ RUN apt-get update && \
apt-get install -y --no-install-recommends curl-kphp-vk kphp-timelib libuber-h3-dev libfmt-dev libgtest-dev libgmock-dev libre2-dev libpcre3-dev \
libzstd-dev libyaml-cpp-dev libnghttp2-dev zlib1g-dev php7.4-dev mysql-server libmysqlclient-dev libldap-dev libkrb5-dev \
postgresql postgresql-server-dev-all libnuma-dev composer unzip && \
pip3 install portalocker psutil requests-toolbelt pytest pytest-xdist pytest-mysql pytest-postgresql psycopg zstandard && \
pip3 install portalocker psutil urllib3 requests-toolbelt pytest pytest-xdist pytest-mysql pytest-postgresql psycopg zstandard && \
rm -rf /var/lib/apt/lists/*

ENV ASAN_OPTIONS=detect_leaks=0
ENV ASAN_OPTIONS=detect_leaks=0:detect_stack_use_after_return=1
ENV UBSAN_OPTIONS=print_stacktrace=1:allow_addr2line=1

RUN useradd -ms /bin/bash kitten
13 changes: 9 additions & 4 deletions .github/workflows/Dockerfile.jammy
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@ RUN apt update && \
add-apt-repository ppa:ondrej/php -y && \
apt update && \
apt install -y --no-install-recommends \
git cmake make g++ lld gperf netcat \
git cmake make g++ lld gperf netcat python3 \
python3-minimal python3-dev libpython3-dev python3-jsonschema python3-setuptools python3-pip && \
apt install -y --no-install-recommends \
php7.4-dev php7.4-common php7.4-bcmath php7.4-mbstring php7.4-curl php7.4-zstd && \
git clone https://github.com/uber/h3.git && cd h3 && git checkout stable-3.x && cmake -DBUILD_SHARED_LIBS=ON . && \
make -j4 && make install && cp /usr/local/lib/libh3.* /usr/lib/ && ldconfig && cd .. && \
git clone https://github.com/neatlife/php-h3.git && cd php-h3 && phpize && ./configure && make && make install && cd .. && \
pip3 install wheel && \
apt install -y --no-install-recommends curl-kphp-vk kphp-timelib libuber-h3-dev libfmt-dev libgtest-dev libgmock-dev libre2-dev libpcre3-dev \
libzstd-dev libyaml-cpp-dev libnghttp2-dev zlib1g-dev php7.4-dev mysql-server libmysqlclient-dev libnuma-dev unzip \
libzstd-dev libyaml-cpp-dev libnghttp2-dev zlib1g-dev mysql-server libmysqlclient-dev libnuma-dev unzip \
libldap-dev libkrb5-dev postgresql postgresql-server-dev-all && \
pip3 install portalocker psutil requests-toolbelt pytest pytest-xdist pytest-mysql pytest-postgresql psycopg zstandard && \
pip3 install portalocker psutil urllib3 requests-toolbelt pytest pytest-xdist pytest-mysql pytest-postgresql psycopg zstandard && \
rm -rf /var/lib/apt/lists/*

# set php7.4 as default
Expand All @@ -32,7 +37,7 @@ RUN update-alternatives --install /usr/bin/ld ld /usr/bin/x86_64-linux-gnu-ld 10
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" && \
php composer-setup.php --install-dir=/usr/bin --filename=composer --version=1.10.26

ENV ASAN_OPTIONS=detect_leaks=0
ENV ASAN_OPTIONS=detect_leaks=0:detect_stack_use_after_return=1
ENV UBSAN_OPTIONS=print_stacktrace=1:allow_addr2line=1

RUN useradd -ms /bin/bash kitten
4 changes: 2 additions & 2 deletions common/parallel/counter-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

TEST(parallel_counter, basic) {
PARALLEL_COUNTER(counter);
const int nr_threads = 8;
const int nr_threads = 2;
auto random_engine = std::default_random_engine();
std::uniform_int_distribution<int> distribution(0, 100000);
std::uniform_int_distribution<int> distribution(0, 1000);

std::vector<std::thread> threads(nr_threads);

Expand Down
6 changes: 3 additions & 3 deletions common/parallel/limit-counter-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
#include "common/parallel/limit-counter.h"

TEST(parallel_limit_counter, basic) {
constexpr std::size_t global_max = 100000;
constexpr std::size_t thread_max = 10000;
constexpr std::size_t global_max = 1000;
constexpr std::size_t thread_max = 100;

PARALLEL_LIMIT_COUNTER(limit_counter);
PARALLEL_LIMIT_COUNTER_INIT(limit_counter, global_max, thread_max);

constexpr int nr_threads = 8;
constexpr int nr_threads = 2;
std::mt19937 random_engine(std::random_device{}());
std::uniform_int_distribution<int> distribution(0, thread_max);

Expand Down
6 changes: 5 additions & 1 deletion runtime/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1881,13 +1881,17 @@ int32_t ini_set_from_config(const char *config_file_name) {
if (pos == std::string::npos) {
return line_num;
}
fprintf(stdout, "INI_SET: %s, %s = %s", config_file_name,
string(line.substr(0, pos).data(), static_cast<string::size_type>(line.substr(0, pos).size())).c_str(),
string(line.substr(pos + 1).data(), static_cast<string::size_type>(line.substr(pos + 1).size())).c_str());
ini_set(line.substr(0, pos), line.substr(pos + 1));
}
return 0;
}

Optional<string> f$ini_get(const string &s) {
if (ini_vars != nullptr && ini_vars->has_key(s)) {
fprintf(stdout, "INI_GET: %s, %d, %d", s.c_str(), ini_vars != nullptr, ini_vars->has_key(s));
if (ini_vars != nullptr && ini_vars->has_key(s)) {
return ini_vars->get_value(s);
}

Expand Down
27 changes: 22 additions & 5 deletions server/php-runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,13 @@ void PhpScript::error(const char *error_message, script_error_t error_type) noex
current_script->error_message = error_message;
current_script->error_type = error_type;
stack_end = reinterpret_cast<char *>(exit_context.uc_stack.ss_sp) + exit_context.uc_stack.ss_size;
#if ASAN_ENABLED
__sanitizer_start_switch_fiber(nullptr, main_thread_stack, main_thread_stacksize);
#endif
setcontext_portable(&exit_context);
#if ASAN_ENABLED
__sanitizer_start_switch_fiber(nullptr, main_thread_stack, main_thread_stacksize);
#endif
setcontext_portable(&exit_context);
#if ASAN_ENABLED
__sanitizer_finish_switch_fiber(nullptr, &main_thread_stack, &main_thread_stacksize);
#endif
}

void PhpScript::check_delayed_errors() noexcept {
Expand Down Expand Up @@ -165,12 +168,26 @@ void PhpScript::init(script_t *script, php_query_data *data_to_set) noexcept {

assert_state(run_state_t::before_init);

#if ASAN_ENABLED
__sanitizer_start_switch_fiber(nullptr, main_thread_stack, main_thread_stacksize);
#endif
getcontext_portable(&run_context);
#if ASAN_ENABLED
__sanitizer_finish_switch_fiber(nullptr, &main_thread_stack, &main_thread_stacksize);
#endif

run_context.uc_stack.ss_sp = script_stack.get_stack_ptr();
run_context.uc_stack.ss_size = script_stack.get_stack_size();
run_context.uc_link = nullptr;
makecontext_portable(&run_context, &script_context_entrypoint, 0);

#if ASAN_ENABLED
__sanitizer_start_switch_fiber(nullptr, main_thread_stack, main_thread_stacksize);
#endif
makecontext_portable(&run_context, &script_context_entrypoint, 0);
#if ASAN_ENABLED
__sanitizer_finish_switch_fiber(nullptr, &main_thread_stack, &main_thread_stacksize);
#endif

run_main = script;
data = data_to_set;

Expand Down
19 changes: 11 additions & 8 deletions tests/python/lib/http_client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from requests_toolbelt.utils import dump
import requests
import socket
from urllib.request import urlopen, Request

from .colors import blue

Expand All @@ -23,15 +24,17 @@ def __init__(self, raw_bytes):


def send_http_request(port, uri='/', method='GET', timeout=30, **kwargs):
session = requests.session()
# session = requests.session()
# url = 'http://127.0.0.1:{}{}'.format(port, uri)
# print("\nSending HTTP request: [{}]".format(blue(url)))
# r = session.request(method=method, url=url, timeout=timeout, **kwargs)
# session.close()
# print("HTTP request debug:")
# print("=============================")
# print(*[i for i in dump.dump_all(r).splitlines(True)], sep="\n")
# print("=============================")
url = 'http://127.0.0.1:{}{}'.format(port, uri)
print("\nSending HTTP request: [{}]".format(blue(url)))
r = session.request(method=method, url=url, timeout=timeout, **kwargs)
session.close()
print("HTTP request debug:")
print("=============================")
print(*[i for i in dump.dump_all(r).splitlines(True)], sep="\n")
print("=============================")
r = urlopen(Request(method=method, url=url)).read().decode('utf-8')
return r


Expand Down
4 changes: 3 additions & 1 deletion tests/python/lib/stats_receiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ def wait_next_stats(self, timeout=60):

def try_update_stats(self):
new_stats = {}
for stat_line in filter(None, self._stats_file_read_fd.readlines()):
lines = self._stats_file_read_fd.readlines()
for stat_line in filter(None, lines):
if stat_line[-1] != "\n":
print(lines)
raise RuntimeError("Got bad stat line: {}".format(stat_line))
stat, value = stat_line.split(":")
value, _ = value.split("|")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def test_store_fetch_delete(self):

resp = self.kphp_server.http_post(
uri="/fetch_and_verify",
json={"key": "key{}".format(i)})
json={"key": f"key{i}"})
self.assertEqual(resp.status_code, 200)
self.assertEqual(resp.json(), {"a": True, "b": True, "c": True})

Expand Down
36 changes: 34 additions & 2 deletions tests/python/tests/job_workers/test_job_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,40 @@ def test_job_exception_error(self):
])

def test_job_stack_overflow_error(self):
self.job_error_test_impl("stack_overflow", self.JOB_STACK_OVERFLOW_ERROR, data=[[1, 2, 3, 4, 5]], buffers=2)
self.kphp_server.assert_log([
error_code = self.JOB_STACK_OVERFLOW_ERROR
data = [[1, 2, 3, 4], [7, 9, 12]]
buffers = 4
stats_before = self.kphp_server.get_stats()
resp = self.kphp_server.http_post(
uri="/test_job_errors",
json={
"tag": "x2_with_error",
"error-type": "stack_overflow",
"data": data
})
self.assertEqual(resp.status_code, 200)

job_result = resp.json()["jobs-result"]
results = 2

eq = 0
got_error_code = ''
for i in range(results):
if job_result[i]["error_code"] == error_code: eq += 1
else: got_error_code = job_result[i]["error_code"]
if eq == 0: self.assertEqual(got_error_code, error_code)

corr_buffers = buffers-(results-eq)

self.kphp_server.assert_stats(
initial_stats=stats_before,
expected_added_stats={
"kphp_server.workers_job_memory_messages_shared_messages_buffers_acquired": corr_buffers,
"kphp_server.workers_job_memory_messages_shared_messages_buffers_released": corr_buffers,
"kphp_server.workers_job_memory_messages_shared_messages_buffer_acquire_fails": 0
})

self.kphp_server.assert_log(eq * [
"Critical error during script execution: sigsegv\\(stack overflow\\)",
"Error -1: Callstack overflow"
])
Expand Down