Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Calamares
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
osak
Calamares
Commits
f4c5b904
Commit
f4c5b904
authored
Jun 27, 2014
by
Aurélien Gâteau
Browse files
Options
Downloads
Patches
Plain Diff
Make it possible to test with other devices
parent
23e91ee4
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/calapmtest.cpp
+52
-9
52 additions, 9 deletions
tests/calapmtest.cpp
with
52 additions
and
9 deletions
tests/calapmtest.cpp
+
52
−
9
View file @
f4c5b904
...
@@ -16,6 +16,7 @@
...
@@ -16,6 +16,7 @@
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#include
<QCommandLineParser>
#include
<QCoreApplication>
#include
<QCoreApplication>
#include
<QDebug>
#include
<QDebug>
#include
<QScopedPointer>
#include
<QScopedPointer>
...
@@ -37,8 +38,6 @@
...
@@ -37,8 +38,6 @@
#include
<iostream>
#include
<iostream>
using
namespace
std
;
using
namespace
std
;
static
const
char
*
SCRATCH_DEVICE_NAME
=
"/dev/sdb"
;
static
ostream
&
operator
<<
(
ostream
&
out
,
const
QString
&
s
)
static
ostream
&
operator
<<
(
ostream
&
out
,
const
QString
&
s
)
{
{
return
out
<<
qPrintable
(
s
);
return
out
<<
qPrintable
(
s
);
...
@@ -72,11 +71,11 @@ void showInfo( CoreBackend* backend )
...
@@ -72,11 +71,11 @@ void showInfo( CoreBackend* backend )
qDeleteAll
(
devices
);
qDeleteAll
(
devices
);
}
}
void
wipe
(
CoreBackend
*
backend
)
void
wipe
(
CoreBackend
*
backend
,
const
QString
devicePath
)
{
{
Report
report
(
0
);
Report
report
(
0
);
QScopedPointer
<
Device
>
device
(
backend
->
scanDevice
(
SCRATCH_DEVICE_NAME
)
);
QScopedPointer
<
Device
>
device
(
backend
->
scanDevice
(
devicePath
)
);
Q_ASSERT
(
device
.
data
()
);
Q_ASSERT
(
device
.
data
()
);
QScopedPointer
<
CoreBackendDevice
>
backendDevice
(
backend
->
openDevice
(
device
->
deviceNode
()
)
);
QScopedPointer
<
CoreBackendDevice
>
backendDevice
(
backend
->
openDevice
(
device
->
deviceNode
()
)
);
...
@@ -147,11 +146,11 @@ bool createPartition( CoreBackend* backend, Report* report, Device* device, Part
...
@@ -147,11 +146,11 @@ bool createPartition( CoreBackend* backend, Report* report, Device* device, Part
return
true
;
return
true
;
}
}
void
createPartitions
(
CoreBackend
*
backend
)
void
createPartitions
(
CoreBackend
*
backend
,
const
QString
&
devicePath
)
{
{
Report
report
(
0
);
Report
report
(
0
);
QScopedPointer
<
Device
>
device
(
backend
->
scanDevice
(
SCRATCH_DEVICE_NAME
)
);
QScopedPointer
<
Device
>
device
(
backend
->
scanDevice
(
devicePath
)
);
Q_ASSERT
(
device
.
data
()
);
Q_ASSERT
(
device
.
data
()
);
PartitionTable
*
table
=
device
->
partitionTable
();
PartitionTable
*
table
=
device
->
partitionTable
();
...
@@ -181,10 +180,34 @@ void createPartitions( CoreBackend* backend )
...
@@ -181,10 +180,34 @@ void createPartitions( CoreBackend* backend )
}
}
}
}
bool
confirm
(
const
QString
&
devicePath
)
{
cout
<<
"WARNING: This operation will destruct any data on device "
<<
devicePath
<<
"!
\n
"
;
cout
<<
"Continue? [yn]: "
;
string
answer
;
cin
>>
answer
;
return
answer
==
"y"
;
}
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
argc
,
char
**
argv
)
{
{
QCoreApplication
app
(
argc
,
argv
);
QCoreApplication
app
(
argc
,
argv
);
// Parse arguments
QCommandLineParser
parser
;
parser
.
addHelpOption
();
parser
.
addPositionalArgument
(
"action"
,
"Must be one of 'info', 'wipe', 'partitions'"
);
parser
.
addPositionalArgument
(
"device"
,
"Device to work on. Must be a disk, not a partition (not required for 'info')"
);
parser
.
process
(
app
);
QStringList
args
=
parser
.
positionalArguments
();
if
(
args
.
empty
()
)
{
cerr
<<
"Missing arguments. Try --help
\n
"
;
return
1
;
}
// Starts
if
(
!
CalaPM
::
init
()
)
if
(
!
CalaPM
::
init
()
)
{
{
return
1
;
return
1
;
...
@@ -192,18 +215,38 @@ int main( int argc, char** argv )
...
@@ -192,18 +215,38 @@ int main( int argc, char** argv )
CoreBackend
*
backend
=
CoreBackendManager
::
self
()
->
backend
();
CoreBackend
*
backend
=
CoreBackendManager
::
self
()
->
backend
();
Q_ASSERT
(
backend
);
Q_ASSERT
(
backend
);
QString
cmd
(
arg
v
[
1
]
)
;
QString
cmd
=
arg
s
[
0
]
;
if
(
cmd
==
"info"
)
if
(
cmd
==
"info"
)
{
{
showInfo
(
backend
);
showInfo
(
backend
);
}
}
else
if
(
cmd
==
"wipe"
)
else
if
(
cmd
==
"wipe"
)
{
{
wipe
(
backend
);
if
(
args
.
length
()
<
2
)
{
cerr
<<
"Missing device argument. Try --help
\n
"
;
return
1
;
}
QString
device
=
args
[
1
];
if
(
!
confirm
(
device
)
)
{
return
1
;
}
wipe
(
backend
,
device
);
}
}
else
if
(
cmd
==
"partitions"
)
else
if
(
cmd
==
"partitions"
)
{
{
createPartitions
(
backend
);
if
(
args
.
length
()
<
2
)
{
cerr
<<
"Missing device argument. Try --help
\n
"
;
return
1
;
}
QString
device
=
args
[
1
];
if
(
!
confirm
(
device
)
)
{
return
1
;
}
createPartitions
(
backend
,
device
);
}
}
else
else
{
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment