loggerd: make test_loggerd.py run on PC (#23574)
* run on PC * set frameId * remove todo * rawlogger: remove suffix mkv * remove unused import PC Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>pull/23573/head
parent
783db0cf33
commit
22d43211d9
|
@ -20,17 +20,16 @@ public:
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace Path {
|
namespace Path {
|
||||||
inline static std::string HOME = util::getenv("HOME");
|
|
||||||
inline std::string log_root() {
|
inline std::string log_root() {
|
||||||
if (const char *env = getenv("LOG_ROOT")) {
|
if (const char *env = getenv("LOG_ROOT")) {
|
||||||
return env;
|
return env;
|
||||||
}
|
}
|
||||||
return Hardware::PC() ? HOME + "/.comma/media/0/realdata" : "/data/media/0/realdata";
|
return Hardware::PC() ? util::getenv("HOME") + "/.comma/media/0/realdata" : "/data/media/0/realdata";
|
||||||
}
|
}
|
||||||
inline std::string params() {
|
inline std::string params() {
|
||||||
return Hardware::PC() ? HOME + "/.comma/params" : "/data/params";
|
return Hardware::PC() ? util::getenv("HOME") + "/.comma/params" : "/data/params";
|
||||||
}
|
}
|
||||||
inline std::string rsa_file() {
|
inline std::string rsa_file() {
|
||||||
return Hardware::PC() ? HOME + "/.comma/persist/comma/id_rsa" : "/persist/comma/id_rsa";
|
return Hardware::PC() ? util::getenv("HOME") + "/.comma/persist/comma/id_rsa" : "/persist/comma/id_rsa";
|
||||||
}
|
}
|
||||||
} // namespace Path
|
} // namespace Path
|
||||||
|
|
|
@ -80,7 +80,7 @@ const LogCameraInfo cameras_logged[] = {
|
||||||
.downscale = false,
|
.downscale = false,
|
||||||
.has_qcamera = false,
|
.has_qcamera = false,
|
||||||
.trigger_rotate = Hardware::TICI(),
|
.trigger_rotate = Hardware::TICI(),
|
||||||
.enable = !Hardware::PC(),
|
.enable = true,
|
||||||
.record = Params().getBool("RecordFront"),
|
.record = Params().getBool("RecordFront"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -64,7 +64,7 @@ RawLogger::~RawLogger() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void RawLogger::encoder_open(const char* path) {
|
void RawLogger::encoder_open(const char* path) {
|
||||||
vid_path = util::string_format("%s/%s.mkv", path, filename);
|
vid_path = util::string_format("%s/%s", path, filename);
|
||||||
|
|
||||||
// create camera lock file
|
// create camera lock file
|
||||||
lock_path = util::string_format("%s/%s.lock", path, filename);
|
lock_path = util::string_format("%s/%s.lock", path, filename);
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
import numpy as np
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
import string
|
import string
|
||||||
|
@ -14,12 +15,14 @@ from cereal.services import service_list
|
||||||
from common.basedir import BASEDIR
|
from common.basedir import BASEDIR
|
||||||
from common.params import Params
|
from common.params import Params
|
||||||
from common.timeout import Timeout
|
from common.timeout import Timeout
|
||||||
from selfdrive.hardware import PC, TICI
|
from selfdrive.hardware import TICI
|
||||||
from selfdrive.loggerd.config import ROOT
|
from selfdrive.loggerd.config import ROOT
|
||||||
from selfdrive.manager.process_config import managed_processes
|
from selfdrive.manager.process_config import managed_processes
|
||||||
from selfdrive.test.helpers import with_processes
|
|
||||||
from selfdrive.version import get_version
|
from selfdrive.version import get_version
|
||||||
from tools.lib.logreader import LogReader
|
from tools.lib.logreader import LogReader
|
||||||
|
from cereal.visionipc.visionipc_pyx import VisionIpcServer, VisionStreamType # pylint: disable=no-name-in-module, import-error
|
||||||
|
from common.transformations.camera import eon_f_frame_size, tici_f_frame_size, \
|
||||||
|
eon_d_frame_size, tici_d_frame_size, tici_e_frame_size
|
||||||
|
|
||||||
SentinelType = log.Sentinel.SentinelType
|
SentinelType = log.Sentinel.SentinelType
|
||||||
|
|
||||||
|
@ -28,12 +31,6 @@ CEREAL_SERVICES = [f for f in log.Event.schema.union_fields if f in service_list
|
||||||
|
|
||||||
|
|
||||||
class TestLoggerd(unittest.TestCase):
|
class TestLoggerd(unittest.TestCase):
|
||||||
# TODO: all tests should work on PC
|
|
||||||
@classmethod
|
|
||||||
def setUpClass(cls):
|
|
||||||
if PC:
|
|
||||||
raise unittest.SkipTest
|
|
||||||
|
|
||||||
def _get_latest_log_dir(self):
|
def _get_latest_log_dir(self):
|
||||||
log_dirs = sorted(Path(ROOT).iterdir(), key=lambda f: f.stat().st_mtime)
|
log_dirs = sorted(Path(ROOT).iterdir(), key=lambda f: f.stat().st_mtime)
|
||||||
return log_dirs[-1]
|
return log_dirs[-1]
|
||||||
|
@ -107,25 +104,41 @@ class TestLoggerd(unittest.TestCase):
|
||||||
for _, k, v in fake_params:
|
for _, k, v in fake_params:
|
||||||
self.assertEqual(getattr(initData, k), v)
|
self.assertEqual(getattr(initData, k), v)
|
||||||
|
|
||||||
# TODO: this shouldn't need camerad
|
|
||||||
@with_processes(['camerad'])
|
|
||||||
def test_rotation(self):
|
def test_rotation(self):
|
||||||
os.environ["LOGGERD_TEST"] = "1"
|
os.environ["LOGGERD_TEST"] = "1"
|
||||||
Params().put("RecordFront", "1")
|
Params().put("RecordFront", "1")
|
||||||
|
|
||||||
expected_files = {"rlog.bz2", "qlog.bz2", "qcamera.ts", "fcamera.hevc", "dcamera.hevc"}
|
expected_files = {"rlog.bz2", "qlog.bz2", "qcamera.ts", "fcamera.hevc", "dcamera.hevc"}
|
||||||
|
streams = [(VisionStreamType.VISION_STREAM_ROAD, tici_f_frame_size if TICI else eon_f_frame_size, "roadCameraState"),
|
||||||
|
(VisionStreamType.VISION_STREAM_DRIVER, tici_d_frame_size if TICI else eon_d_frame_size, "driverCameraState")]
|
||||||
if TICI:
|
if TICI:
|
||||||
expected_files.add("ecamera.hevc")
|
expected_files.add("ecamera.hevc")
|
||||||
|
streams.append((VisionStreamType.VISION_STREAM_WIDE_ROAD, tici_e_frame_size, "wideRoadCameraState"))
|
||||||
|
|
||||||
# give camerad time to start
|
pm = messaging.PubMaster(["roadCameraState", "driverCameraState", "wideRoadCameraState"])
|
||||||
time.sleep(3)
|
vipc_server = VisionIpcServer("camerad")
|
||||||
|
for stream_type, frame_size, _ in streams:
|
||||||
|
vipc_server.create_buffers(stream_type, 40, False, *(frame_size))
|
||||||
|
vipc_server.start_listener()
|
||||||
|
|
||||||
for _ in range(5):
|
for _ in range(5):
|
||||||
num_segs = random.randint(2, 5)
|
num_segs = random.randint(2, 5)
|
||||||
length = random.randint(1, 3)
|
length = random.randint(1, 3)
|
||||||
os.environ["LOGGERD_SEGMENT_LENGTH"] = str(length)
|
os.environ["LOGGERD_SEGMENT_LENGTH"] = str(length)
|
||||||
|
|
||||||
managed_processes["loggerd"].start()
|
managed_processes["loggerd"].start()
|
||||||
time.sleep(num_segs*length + 1)
|
|
||||||
|
fps = 20.0
|
||||||
|
for n in range(1, int(num_segs*length*fps)+1):
|
||||||
|
for stream_type, frame_size, state in streams:
|
||||||
|
dat = np.empty(int(frame_size[0]*frame_size[1]*3/2), dtype=np.uint8)
|
||||||
|
vipc_server.send(stream_type, dat[:].flatten().tobytes(), n, n/fps, n/fps)
|
||||||
|
|
||||||
|
camera_state = messaging.new_message(state)
|
||||||
|
frame = getattr(camera_state, state)
|
||||||
|
frame.frameId = n
|
||||||
|
pm.send(state, camera_state)
|
||||||
|
time.sleep(1.0/fps)
|
||||||
|
|
||||||
managed_processes["loggerd"].stop()
|
managed_processes["loggerd"].stop()
|
||||||
|
|
||||||
route_path = str(self._get_latest_log_dir()).rsplit("--", 1)[0]
|
route_path = str(self._get_latest_log_dir()).rsplit("--", 1)[0]
|
||||||
|
|
Loading…
Reference in New Issue