mirror of
https://github.com/ElvishArtisan/rivendell.git
synced 2025-12-17 14:11:14 +01:00
2025-12-02 Fred Gleason <fredg@paravelsystems.com>
* Added a 'dropbox_copy_test' test harness in 'tests/'. Signed-off-by: Fred Gleason <fredg@paravelsystems.com>
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -146,6 +146,7 @@ tests/dateparse_test
|
|||||||
tests/db_charset_test
|
tests/db_charset_test
|
||||||
tests/delete_test
|
tests/delete_test
|
||||||
tests/download_test
|
tests/download_test
|
||||||
|
tests/dropbox_copy_test
|
||||||
tests/feed_image_test
|
tests/feed_image_test
|
||||||
tests/getpids_test
|
tests/getpids_test
|
||||||
tests/gpio_fuzz_test
|
tests/gpio_fuzz_test
|
||||||
|
|||||||
@@ -25090,3 +25090,5 @@
|
|||||||
and 'RDDropbox::setDropBoxScanInterval()' methods.
|
and 'RDDropbox::setDropBoxScanInterval()' methods.
|
||||||
* Added an 'Advanced Settings' button to the 'Edit Dropbox' dialog
|
* Added an 'Advanced Settings' button to the 'Edit Dropbox' dialog
|
||||||
in rdadmin(1).
|
in rdadmin(1).
|
||||||
|
2025-12-02 Fred Gleason <fredg@paravelsystems.com>
|
||||||
|
* Added a 'dropbox_copy_test' test harness in 'tests/'.
|
||||||
|
|||||||
156
tests/dropbox_copy_test.cpp
Normal file
156
tests/dropbox_copy_test.cpp
Normal file
@@ -0,0 +1,156 @@
|
|||||||
|
// dropbox_copy_test.cpp
|
||||||
|
//
|
||||||
|
// Generate multiple slow file transfers for testing dropboxes
|
||||||
|
//
|
||||||
|
// (C) Copyright 2025 Fred Gleason <fredg@paravelsystems.com>
|
||||||
|
//
|
||||||
|
// This program is free software; you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License version 2 as
|
||||||
|
// published by the Free Software Foundation.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public
|
||||||
|
// License along with this program; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
#include <QCoreApplication>
|
||||||
|
|
||||||
|
#include <rdapplication.h>
|
||||||
|
#include <rdcmd_switch.h>
|
||||||
|
|
||||||
|
#include "dropbox_copy_test.h"
|
||||||
|
|
||||||
|
MainObject::MainObject(QObject *parent)
|
||||||
|
: QObject(parent)
|
||||||
|
{
|
||||||
|
bool ok=false;
|
||||||
|
RDCmdSwitch *cmd=new RDCmdSwitch("dropbox_copy_test",DROPBOX_COPY_TEST_USAGE);
|
||||||
|
|
||||||
|
d_bytes_size=1024;
|
||||||
|
d_gap_size=0;
|
||||||
|
d_output_dir=QDir(".");
|
||||||
|
|
||||||
|
for(unsigned i=0;i<cmd->keys();i++) {
|
||||||
|
if(cmd->key(i)=="--xfer-size") {
|
||||||
|
int blocks=cmd->value(i).toInt(&ok);
|
||||||
|
if((!ok)||(blocks<=0)) {
|
||||||
|
fprintf(stderr,"dropbox_copy_test: invalid argument\n");
|
||||||
|
exit(RDApplication::ExitInvalidOption);
|
||||||
|
}
|
||||||
|
d_bytes_size=1024*blocks;
|
||||||
|
cmd->setProcessed(i,true);
|
||||||
|
}
|
||||||
|
if(cmd->key(i)=="--gap-size") {
|
||||||
|
d_gap_size=cmd->value(i).toInt(&ok);
|
||||||
|
if((!ok)||(d_gap_size<0)) {
|
||||||
|
fprintf(stderr,"dropbox_copy_test: invalid argument\n");
|
||||||
|
exit(RDApplication::ExitInvalidOption);
|
||||||
|
}
|
||||||
|
cmd->setProcessed(i,true);
|
||||||
|
}
|
||||||
|
if(cmd->key(i)=="--in") {
|
||||||
|
d_input_filenames.push_back(cmd->value(i));
|
||||||
|
cmd->setProcessed(i,true);
|
||||||
|
}
|
||||||
|
if(cmd->key(i)=="--out") {
|
||||||
|
d_output_dir=QDir(cmd->value(i));
|
||||||
|
if(!d_output_dir.exists()) {
|
||||||
|
fprintf(stderr,"dropbox_copy_test: no such directory\n");
|
||||||
|
exit(RDApplication::ExitInvalidOption);
|
||||||
|
}
|
||||||
|
cmd->setProcessed(i,true);
|
||||||
|
}
|
||||||
|
if(!cmd->processed(i)) {
|
||||||
|
fprintf(stderr,"dropbox_copy_test: unrecognized option \"%s\"\n",
|
||||||
|
cmd->key(i).toUtf8().constData());
|
||||||
|
exit(RDApplication::ExitInvalidOption);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Transfer Size: %d octets\n",d_bytes_size);
|
||||||
|
printf("Gap Size: %d s\n",d_gap_size);
|
||||||
|
for(int i=0;i<d_input_filenames.size();i++) {
|
||||||
|
CopyFile(d_input_filenames.at(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MainObject::CopyFile(const QString &filename) const
|
||||||
|
{
|
||||||
|
struct stat statbuf;
|
||||||
|
int n;
|
||||||
|
int src_fd=-1;
|
||||||
|
int dst_fd=-1;
|
||||||
|
|
||||||
|
uint8_t *data=(uint8_t *)malloc(d_bytes_size);
|
||||||
|
for(int i=0;i<d_input_filenames.size();i++) {
|
||||||
|
printf("%s ",d_input_filenames.at(i).toUtf8().constData());
|
||||||
|
fflush(stdout);
|
||||||
|
if((src_fd=open(d_input_filenames.at(i).toUtf8(),O_RDONLY))<0) {
|
||||||
|
printf("%s, skipping\n",strerror(errno));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
memset(&statbuf,0,sizeof(statbuf));
|
||||||
|
if(fstat(src_fd,&statbuf)!=0) {
|
||||||
|
printf("%s, skipping\n",strerror(errno));
|
||||||
|
close(src_fd);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
QString outfile=d_output_dir.path();
|
||||||
|
if(outfile.right(1)!="/") {
|
||||||
|
outfile+="/";
|
||||||
|
}
|
||||||
|
outfile+=d_input_filenames.at(i).split("/",Qt::SkipEmptyParts).last();
|
||||||
|
printf("=> %s ",outfile.toUtf8().constData());
|
||||||
|
fflush(stdout);
|
||||||
|
if((dst_fd=open(outfile.toUtf8(),O_CREAT|O_TRUNC|O_WRONLY,statbuf.st_mode))<0) {
|
||||||
|
printf("%s, skipping\n",strerror(errno));
|
||||||
|
close(src_fd);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
while((n=read(src_fd,data,d_bytes_size))>0) {
|
||||||
|
if(write(dst_fd,data,n)!=n) {
|
||||||
|
printf("write error [%s]\n",strerror(errno));
|
||||||
|
close(dst_fd);
|
||||||
|
close(src_fd);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
printf(".");
|
||||||
|
fflush(stdout);
|
||||||
|
sleep(d_gap_size);
|
||||||
|
}
|
||||||
|
if(n==0) {
|
||||||
|
printf("done.\n");
|
||||||
|
}
|
||||||
|
else {// Read error
|
||||||
|
printf("read error [%s]\n",strerror(errno));
|
||||||
|
}
|
||||||
|
close(dst_fd);
|
||||||
|
close(src_fd);
|
||||||
|
}
|
||||||
|
free(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc,char *argv[])
|
||||||
|
{
|
||||||
|
QCoreApplication a(argc,argv);
|
||||||
|
|
||||||
|
new MainObject();
|
||||||
|
|
||||||
|
return a.exec();
|
||||||
|
}
|
||||||
44
tests/dropbox_copy_test.h
Normal file
44
tests/dropbox_copy_test.h
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
// dropbox_copy_test.h
|
||||||
|
//
|
||||||
|
// Generate multiple slow file transfers for testing dropboxes
|
||||||
|
//
|
||||||
|
// (C) Copyright 2025 Fred Gleason <fredg@paravelsystems.com>
|
||||||
|
//
|
||||||
|
// This program is free software; you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License version 2 as
|
||||||
|
// published by the Free Software Foundation.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public
|
||||||
|
// License along with this program; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef DROPBOX_COPY_TEST_H
|
||||||
|
#define DROPBOX_COPY_TEST_H
|
||||||
|
|
||||||
|
#include <QDir>
|
||||||
|
#include <QObject>
|
||||||
|
#include <QStringList>
|
||||||
|
|
||||||
|
#define DROPBOX_COPY_TEST_USAGE "[options]\n\nPerform multiple slow file transfer for testing dropboxes\n\nOptions are:\n--in=<filename>\n\n--out=<dirname>\n\n--xfer-size=<blocks>\n\n--gap-size=<seconds>\n\n"
|
||||||
|
|
||||||
|
class MainObject : public QObject
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
MainObject(QObject *parent=0);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void CopyFile(const QString &filename) const;
|
||||||
|
QStringList d_input_filenames;
|
||||||
|
QDir d_output_dir;
|
||||||
|
int d_bytes_size;
|
||||||
|
int d_gap_size;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // DROPBOX_COPY_TEST_H
|
||||||
Reference in New Issue
Block a user