Testing embedded Linux framebuffer display drivers (/dev/fb0) directly from C involves fetching display resolutions via ioctl and mapping raw pixel buffer memory into userspace via mmap().

Linux Framebuffer Test C Program

fb_test.cc
#include <fcntl.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <sys/mmap.h>
#include <unistd.h>
#include <linux/fb.h>
 
int main(void) {
    int fb_fd = open("/dev/fb0", O_RDWR);
    if (fb_fd < 0) {
        perror("Cannot open /dev/fb0");
        return 1;
    }
 
    struct fb_var_screeninfo vinfo;
    ioctl(fb_fd, FBIOGET_VSCREENINFO, &vinfo);
    printf("Resolution: %dx%d, %dbpp\n", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel);
 
    size_t screensize = vinfo.xres * vinfo.yres * (vinfo.bits_per_pixel / 8);
    char *fbp = mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fb_fd, 0);
 
    // Paint red test pixel pattern
    for (size_t i = 0; i < screensize; i += 4) {
        fbp[i] = 0;        // Blue
        fbp[i+1] = 0;      // Green
        fbp[i+2] = (char)255; // Red
        fbp[i+3] = 0;      // Alpha
    }
 
    munmap(fbp, screensize);
    close(fb_fd);
    return 0;
}