2020-04-21 03:26:41 +00:00
|
|
|
#include "main.h"
|
|
|
|
#include <cerrno>
|
|
|
|
#include <mutex>
|
|
|
|
#include <cstring>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
2020-04-28 04:27:07 +00:00
|
|
|
#include "internal.h"
|
2020-04-21 03:26:41 +00:00
|
|
|
#include <condition_variable>
|
|
|
|
|
|
|
|
std::mutex lock;
|
|
|
|
std::condition_variable cond;
|
|
|
|
bool inline_cancelled = false;
|
|
|
|
|
2020-05-09 01:39:15 +00:00
|
|
|
auto testfdcb(struct ncfdplane* ncfd, const void* buf, size_t s, void* curry) -> int {
|
2020-04-21 03:26:41 +00:00
|
|
|
struct ncplane* n = ncfdplane_plane(ncfd);
|
|
|
|
lock.lock();
|
|
|
|
if(ncplane_putstr(n, static_cast<const char*>(buf)) <= 0){
|
|
|
|
lock.unlock();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
lock.unlock();
|
|
|
|
(void)curry;
|
|
|
|
(void)s;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-05-09 01:39:15 +00:00
|
|
|
auto testfdeof(struct ncfdplane* n, int fderrno, void* curry) -> int {
|
2020-04-28 04:27:07 +00:00
|
|
|
bool* outofline_cancelled = static_cast<bool*>(curry);
|
2020-04-21 03:26:41 +00:00
|
|
|
lock.lock();
|
2020-04-28 04:27:07 +00:00
|
|
|
*outofline_cancelled = true;
|
2020-04-21 03:26:41 +00:00
|
|
|
lock.unlock();
|
|
|
|
cond.notify_one();
|
|
|
|
(void)n;
|
|
|
|
(void)fderrno;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-05-09 01:39:15 +00:00
|
|
|
auto testfdeofdestroys(struct ncfdplane* n, int fderrno, void* curry) -> int {
|
2020-04-21 03:26:41 +00:00
|
|
|
lock.lock();
|
|
|
|
inline_cancelled = true;
|
|
|
|
int ret = ncfdplane_destroy(n);
|
|
|
|
lock.unlock();
|
|
|
|
cond.notify_one();
|
|
|
|
(void)curry;
|
|
|
|
(void)fderrno;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
// test ncfdplanes and ncsubprocs
|
2020-05-22 07:31:03 +00:00
|
|
|
TEST_CASE("FdsAndSubprocs"
|
Fully general ncvisual layer (#647)
This represents an essentially complete rewrite of ncvisual and associated code. It had two major goals:
Improve the ncvisual API based off lessons learned, pursuant to the upcoming API freeze. In particular, I wanted to:
decouple ncvisuals from ncplanes. It should be possible to render a ncvisual to multiple planes, with different scaling each time. It should be possible to create an ncvisual without a plane, etc.
normalize the various ways of constructing an ncvisual -- file, memory, plane, etc.
Support multiple blitters, from 7-bit ASCII to Sixel. This required writing the blitters in several cases, and they're not yet in their final implementations (but the API is fine)
I have not yet unified Plots and Visuals, and might not, given that the Plot code works fine. We could at this point implement Plots in terms of Visuals, though -- the blitter backend range has been unified. Sixel is not yet implemented, though it is listed.
There is a new POC tool, blitter. It renders its arguments using all possible blitter+scaling combinations. Another new POC, resize, displays its argument, then resizes it to the screen size and displays that, explicitly making use of ncvisual_resize() rather than a scaling parameter to ncvisual_render().
This also eliminates some memory leaks and bugs we were seeing in trunk, and brings in Sixel scaffolding.
The C++ wrapper will also need patching back up; I cut most of it down while wrestling with this crap, urk.
Closes #638, #562, and #622.
2020-05-29 01:16:58 +00:00
|
|
|
* doctest::description("Fdplanes and subprocedures")) {
|
2020-04-21 03:26:41 +00:00
|
|
|
notcurses_options nopts{};
|
2020-05-17 11:57:21 +00:00
|
|
|
struct notcurses* nc_ = notcurses_init(&nopts, nullptr);
|
|
|
|
if(!nc_){
|
|
|
|
return;
|
|
|
|
}
|
2020-04-21 03:26:41 +00:00
|
|
|
struct ncplane* n_ = notcurses_stdplane(nc_);
|
|
|
|
REQUIRE(n_);
|
|
|
|
REQUIRE(0 == ncplane_cursor_move_yx(n_, 0, 0));
|
|
|
|
|
|
|
|
// destroy the ncfdplane outside of its own context
|
|
|
|
SUBCASE("FdPlaneDestroyOffline") {
|
2020-04-28 04:27:07 +00:00
|
|
|
bool outofline_cancelled = false;
|
2020-04-21 03:26:41 +00:00
|
|
|
ncfdplane_options opts{};
|
2020-04-28 04:27:07 +00:00
|
|
|
opts.curry = &outofline_cancelled;
|
2020-04-22 19:55:35 +00:00
|
|
|
int fd = open("/dev/null", O_RDONLY|O_CLOEXEC);
|
2020-04-21 03:26:41 +00:00
|
|
|
REQUIRE(0 <= fd);
|
|
|
|
auto ncfdp = ncfdplane_create(n_, &opts, fd, testfdcb, testfdeof);
|
|
|
|
REQUIRE(ncfdp);
|
|
|
|
std::unique_lock<std::mutex> lck(lock);
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
while(!outofline_cancelled){
|
|
|
|
cond.wait(lck);
|
|
|
|
}
|
|
|
|
CHECK(0 == ncfdplane_destroy(ncfdp));
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
lock.unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
// destroy the ncfdplane within its own context, i.e. from the eof callback
|
|
|
|
SUBCASE("FdPlaneDestroyInline") {
|
2020-04-21 05:50:53 +00:00
|
|
|
inline_cancelled = false;
|
2020-04-21 03:26:41 +00:00
|
|
|
ncfdplane_options opts{};
|
|
|
|
opts.curry = n_;
|
2020-04-22 19:55:35 +00:00
|
|
|
int fd = open("/dev/null", O_RDONLY|O_CLOEXEC);
|
2020-04-21 03:26:41 +00:00
|
|
|
REQUIRE(0 <= fd);
|
|
|
|
auto ncfdp = ncfdplane_create(n_, &opts, fd, testfdcb, testfdeofdestroys);
|
|
|
|
REQUIRE(ncfdp);
|
|
|
|
std::unique_lock<std::mutex> lck(lock);
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
while(!inline_cancelled){
|
|
|
|
cond.wait(lck);
|
|
|
|
}
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
lock.unlock();
|
|
|
|
}
|
|
|
|
|
2020-05-02 07:49:16 +00:00
|
|
|
SUBCASE("SubprocDestroyCmdExecFails") {
|
2020-05-09 01:30:45 +00:00
|
|
|
char * const argv[] = { strdup("/dev/nope"), nullptr, };
|
2020-04-28 04:27:07 +00:00
|
|
|
bool outofline_cancelled = false;
|
2020-04-22 19:55:35 +00:00
|
|
|
ncsubproc_options opts{};
|
2020-05-02 15:57:38 +00:00
|
|
|
opts.curry = &outofline_cancelled;
|
2020-04-22 19:55:35 +00:00
|
|
|
auto ncsubp = ncsubproc_createvp(n_, &opts, argv[0], argv, testfdcb, testfdeof);
|
|
|
|
REQUIRE(ncsubp);
|
|
|
|
std::unique_lock<std::mutex> lck(lock);
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
while(!outofline_cancelled){
|
|
|
|
cond.wait(lck);
|
|
|
|
}
|
2020-05-06 23:53:59 +00:00
|
|
|
CHECK(0 != ncsubproc_destroy(ncsubp));
|
2020-05-02 08:34:37 +00:00
|
|
|
// FIXME we ought get indication of an error here! or via callback...
|
|
|
|
// FIXME should be 0 !=, methinks!
|
2020-04-22 19:55:35 +00:00
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
lock.unlock();
|
|
|
|
}
|
|
|
|
|
2020-05-02 07:49:16 +00:00
|
|
|
// FIXME SIGCHLD seems to blow up doctest...
|
|
|
|
SUBCASE("SubprocDestroyCmdSucceeds") {
|
2020-05-09 01:30:45 +00:00
|
|
|
char * const argv[] = { strdup("/bin/cat"), strdup("/dev/null"), nullptr, };
|
2020-04-28 04:27:07 +00:00
|
|
|
bool outofline_cancelled = false;
|
2020-04-22 19:55:35 +00:00
|
|
|
ncsubproc_options opts{};
|
2020-05-02 15:57:38 +00:00
|
|
|
opts.curry = &outofline_cancelled;
|
2020-04-22 19:55:35 +00:00
|
|
|
auto ncsubp = ncsubproc_createvp(n_, &opts, argv[0], argv, testfdcb, testfdeof);
|
|
|
|
REQUIRE(ncsubp);
|
|
|
|
std::unique_lock<std::mutex> lck(lock);
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
while(!outofline_cancelled){
|
|
|
|
cond.wait(lck);
|
|
|
|
}
|
|
|
|
CHECK(0 == ncsubproc_destroy(ncsubp));
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
lock.unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
SUBCASE("SubprocDestroyCmdFailed") {
|
2020-05-09 01:30:45 +00:00
|
|
|
char * const argv[] = { strdup("/bin/cat"), strdup("/dev/nope"), nullptr, };
|
2020-04-28 04:27:07 +00:00
|
|
|
bool outofline_cancelled = false;
|
2020-04-21 05:07:45 +00:00
|
|
|
ncsubproc_options opts{};
|
2020-05-02 15:57:38 +00:00
|
|
|
opts.curry = &outofline_cancelled;
|
2020-04-21 05:07:45 +00:00
|
|
|
auto ncsubp = ncsubproc_createvp(n_, &opts, argv[0], argv, testfdcb, testfdeof);
|
|
|
|
REQUIRE(ncsubp);
|
|
|
|
std::unique_lock<std::mutex> lck(lock);
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
while(!outofline_cancelled){
|
|
|
|
cond.wait(lck);
|
|
|
|
}
|
2020-05-06 23:53:59 +00:00
|
|
|
CHECK(0 != ncsubproc_destroy(ncsubp));
|
2020-04-21 05:07:45 +00:00
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
lock.unlock();
|
2020-04-22 16:53:56 +00:00
|
|
|
}
|
2020-04-21 05:07:45 +00:00
|
|
|
|
2020-05-02 08:34:37 +00:00
|
|
|
SUBCASE("SubprocDestroyCmdHung") {
|
2020-05-09 01:30:45 +00:00
|
|
|
char * const argv[] = { strdup("/bin/cat"), nullptr, };
|
2020-05-02 08:34:37 +00:00
|
|
|
bool outofline_cancelled = false;
|
|
|
|
ncsubproc_options opts{};
|
2020-05-02 15:57:38 +00:00
|
|
|
opts.curry = &outofline_cancelled;
|
2020-05-02 08:34:37 +00:00
|
|
|
auto ncsubp = ncsubproc_createvp(n_, &opts, argv[0], argv, testfdcb, testfdeof);
|
|
|
|
REQUIRE(ncsubp);
|
2020-05-06 23:53:59 +00:00
|
|
|
CHECK(0 != ncsubproc_destroy(ncsubp));
|
2020-05-02 08:34:37 +00:00
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
}
|
|
|
|
|
2020-04-21 03:26:41 +00:00
|
|
|
CHECK(0 == notcurses_stop(nc_));
|
|
|
|
}
|